Unsubscribed from channel, still on channel

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:20:10

Well, if your application can't run in background persistently, you can't call such commands when app transferring to background execution state. You can try to use this callback to perform few requests before PubNub client will be suspended along with your app:

- (void)pubnubClient:(PubNub *)client willSuspendWithBlock:(void(^)(void(^)(void(^)(void))))preSuspensionBlock {

    if ([client isConnected]) {

        preSuspensionBlock(^(void(^completionBlock)(void)){

            // Do last calls here
            // Always call this block as soon as required amount of tasks completed.
            completionBlock();
        }];
    });
  }
}

You are still connected because pubnub didn't send any notification while in background. Even more tricky, it will send the queued notif when coming back to foreground.

In order to have Pubnub run in the background, you have to enable the appropriate background modes. One that needs websockets (pubnub also uses them) Select your project on the left and go to the Capabilities tab. In there you will find all the background modes you can enable. For Pubnub, I hear VOIP and and Location Updates will work.

I personally choose location updates. Keep in mind that Apple will reject your app if you don't use location services for actual location services. Being doing some research with Pubnub it's fine by me but when I'll deploy I might switch to HTTP request since they are allowed to run in the background.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!