Thursday, 1 August 2019

setting delegate of WCSession to nil

I'm using 'WCSession' for the connection between my app and apple watch. I preferred singleton approach. So, I made a shared session:

static Shared_WCSession *sharedInstance = nil;
+(Shared_WCSession*)getSharedInstance {
    @synchronized(self) {
        // If the class variable holding the reference to the single ContentManager object is empty create it.
        if(sharedInstance == nil) {
             sharedInstance = [[Shared_WCSession alloc] init];
        }
    }
     return sharedInstance;
}

Then in start session I set up the delegate for the session:

-(void)startSession {
     if ([WCSession isSupported]) {
        self.session = [WCSession defaultSession];
        self.session.delegate = self;
        [self.session activateSession];
        LOG(@"WCSession is supported");
    }
}

What is the proper way to deallocate the delegate?

According to apple's docs I can do it in the following methods:

sessionDidBecomeInactive(_:) 
sessionDidDeactivate(_:)

If I set the delegate to nil there will this interfere with the performance of my applications?



from setting delegate of WCSession to nil

No comments:

Post a Comment