Unsubscribed from channel, still on channel
Asked Answered
A

2

2

I am using PubNub for an IOS app (IOS SDK 8.0). When I am trying to unsubscribe from a channel on "applicationDidEnterBackground" event, I get the following console output. It says the channel is unsubscribed, but when I check from admin console I am still on the channel. Can you give some advice on this ?

Here is the line I am using in "applicationDidEnterBackground":

PubNub.unsubscribeFromChannel(channelToReceive,{(list, err:PNError!)-> Void in
        if(err != nil){
            println(err.localizedFailureReason)
        } else {
            println("Unsubscribed...")
        }
    })

Here is the PubNub console output after "applicationDidEnterBackground" event:

2014-11-08 14:47:16.585 Chat[263:60b] PubNub (0x14d7a2b0) TRYING TO UNSUBSCRIBE FROM CHANNELS: (
    "PNChannel(0x14d28150) b905359780766"
) (STATE: 'connected')
2014-11-08 14:47:16.587 Chat[263:60b] PubNub (0x14d7a2b0) UNSUBSCRIBE FROM CHANNELS (STATE: 'connected')
2014-11-08 14:47:16.590 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] LEAVING SPECIFIC SET OF CHANNELS... (STATE: 10)
2014-11-08 14:47:16.625 Chat[263:60b] PubNub (0x14d7a2b0) WILL UNSUBSCRIBE FROM CHANNELS: (
    "PNChannel(0x14d28150) b905359780766",
    "PNChannelPresence(0x14dc64f0) b905359780766-pnpres"
) (STATE: 'connected')
2014-11-08 14:47:16.632 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier::WRITE] WRITE BUFFER CONTENT (STATE: 33683456)
2014-11-08 14:47:16.640 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] WILL START REQUEST PROCESSING: <PNLeaveRequest|/v2/presence/sub_key/sub*****7fe/channel/b905359780766/leave?uuid=b905359780766&callback=lv_7cba2&pnsdk=PubNub-ObjC-iOS%2F3.6.7> (STATE: 8)
2014-11-08 14:47:16.645 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] RECONNECTING BY REQUEST... (STATE: 8)
2014-11-08 14:47:16.668 Chat[263:60b] PNReachability (0x14d88c00) PUBNUB SERVICES REACHABILITY CHANGED W/O EVENT [CONNECTED? 1 | NETWORK ADDRESS: 192.168.1.6](FLAGS: 65538)
2014-11-08 14:47:16.673 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] TRYING TO RECONNECT... (STATE: 100792320)
2014-11-08 14:47:16.677 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] DESTROYING STREAMS... (STATE: 100792328)
2014-11-08 14:47:16.684 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] UNSCHEDULE REQUEST SENDING (32795e5c-a2cb-475b-993a-61077ea21744) (STATE: 67237896)
2014-11-08 14:47:16.690 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] DID CANCEL REQUEST: <PNLeaveRequest|/v2/presence/sub_key/sub*****7fe/channel/b905359780766/leave?uuid=b905359780766&callback=lv_7cba2&pnsdk=PubNub-ObjC-iOS%2F3.6.7> (STATE: 0)
2014-11-08 14:47:16.714 Chat[263:60b] PNReachability (0x14d88c00) PUBNUB SERVICES REACHABILITY CHANGED W/O EVENT [CONNECTED? 1 | NETWORK ADDRESS: 192.168.1.6](FLAGS: 65538)
2014-11-08 14:47:16.720 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier::READ] DESTROYING... (STATE: 129032)
2014-11-08 14:47:16.726 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier::READ] DESTROYED. (STATE: 126984)
2014-11-08 14:47:16.731 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier::WRITE] DESTROYING... (STATE: 126984)
2014-11-08 14:47:16.742 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier::WRITE] DESTROYED. (STATE: 122888)
2014-11-08 14:47:16.748 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] READ AND WRITE STREAMS DESTROYED (STATE: 12582920)
2014-11-08 14:47:16.757 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier::WRITE] WRITE CANCELED (STATE: 12582920)
2014-11-08 14:47:29.679 Chat[263:60b] PubNub (0x14d7a2b0) HANDLE APPLICATION ENTERED BACKGROUND (STATE: 'connected')
2014-11-08 14:47:36.587 Chat[263:60b] PubNub (0x14d7a2b0) APPLICATION CAN'T RUN IN BACKGROUND (STATE: 'connected')
2014-11-08 14:47:36.591 Chat[263:60b] PNReachability (0x14d88c00) REACHABILITY OBSEVATION SUSPENDED
2014-11-08 14:47:36.594 Chat[263:60b] PubNub (0x14d7a2b0) SUSPENDING... (STATE: 'connected')
2014-11-08 14:47:36.597 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] TRYING TO SUSPEND (STATE: 10)
2014-11-08 14:47:36.600 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] SUSPENDING... (STATE: 10)
2014-11-08 14:47:36.602 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] TRYING TO DISCONNECT... (BY USER REQUEST? 0) (STATE: 12582912)
2014-11-08 14:47:36.604 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier::READ] DISCONNECTING... (STATE: 12582912)
2014-11-08 14:47:36.606 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] HANDLE STREAM CONNECTION CLOSED (STATE: 8912896)
2014-11-08 14:47:36.611 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier::WRITE] DISCONNECTING... (STATE: 8912896)
2014-11-08 14:47:36.613 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] HANDLE STREAM CONNECTION CLOSED (STATE: 1572864)
2014-11-08 14:47:36.615 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] DISCONNECTED (STATE: 12582912)
2014-11-08 14:47:36.617 Chat[263:60b] PNConnection (0x14d5cd40) [CONNECTION::PNMessagingConnectionIdentifier] NOTIFY DELEGATE ABOUT DISCONNECTION (STATE: 12582912)
2014-11-08 14:47:36.619 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] HANDLE DISCONNECTION EVENT (STATE: 24)
2014-11-08 14:47:36.634 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] LEAVE REQUEST COMPLETED (STATE: 0)
2014-11-08 14:47:36.637 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] PRESENCE 'LEAVE' REQUEST ERROR: Domain=com.pubnub.pubnub; Code=107; Description="PubNub client can't perform request"; Reason="Looks like the client lost it's net connection"; Fix suggestion="Ensure that all network configuration (including any proxy) is correct, and try again."; Associated object=(null)\nCHANNELS: (
    "PNChannel(0x14d28150) b905359780766",
    "PNChannelPresence(0x14dc64f0) b905359780766-pnpres"
)\n(STATE: 0)
2014-11-08 14:47:36.641 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] UNSUBSCRIBED FROM CHANNELS: (
    "PNChannel(0x14d28150) b905359780766",
    "PNChannelPresence(0x14dc64f0) b905359780766-pnpres"
)\n(STATE: 0)
2014-11-08 14:47:36.648 Chat[263:60b] PubNub (0x14d7a2b0) SHOULD CHANNEL PNMessagingConnectionIdentifier (0x14d69800) NOTIFY DELEGATE? 0 (STATE: 'suspended')
2014-11-08 14:47:36.651 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] HANDLE SUSPENSION EVENT (STATE: 24)
2014-11-08 14:47:36.653 Chat[263:60b] PNMessagingChannel (0x14d69800) [CHANNEL::PNMessagingConnectionIdentifier] SUSPENDED (STATE: 160)
2014-11-08 14:47:36.655 Chat[263:60b] PNServiceChannel (0x14d90d00) [CHANNEL::PNServiceConnectionIdentifier] TRYING TO SUSPEND (STATE: 8)
2014-11-08 14:47:36.665 Chat[263:60b] PNServiceChannel (0x14d90d00) [CHANNEL::PNServiceConnectionIdentifier] SUSPENDING... (STATE: 8)
2014-11-08 14:47:36.671 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier] TRYING TO DISCONNECT... (BY USER REQUEST? 0) (STATE: 2226176)
2014-11-08 14:47:36.675 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier::READ] DISCONNECTING... (STATE: 2201600)
2014-11-08 14:47:36.679 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier::READ] DESTROYING... (STATE: 2725888)
2014-11-08 14:47:36.699 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier::READ] DESTROYED. (STATE: 2723840)
2014-11-08 14:47:36.703 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier] HANDLE STREAM CONNECTION CLOSED (STATE: 2723840)
2014-11-08 14:47:36.706 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier::WRITE] DISCONNECTING... (STATE: 2723840)
2014-11-08 14:47:36.710 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier::WRITE] DESTROYING... (STATE: 3772416)
2014-11-08 14:47:36.718 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier::WRITE] DESTROYED. (STATE: 3768320)
2014-11-08 14:47:36.721 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier] HANDLE STREAM CONNECTION CLOSED (STATE: 3768320)
2014-11-08 14:47:36.724 Chat[263:60b] PNConnection (0x14d959d0) [CONNECTION::PNServiceConnectionIdentifier] SUSPENDED (STATE: 12582912)
2014-11-08 14:47:36.727 Chat[263:60b] PNServiceChannel (0x14d90d00) [CHANNEL::PNServiceConnectionIdentifier] HANDLE SUSPENSION EVENT (STATE: 24)
2014-11-08 14:47:36.739 Chat[263:60b] PNServiceChannel (0x14d90d00) [CHANNEL::PNServiceConnectionIdentifier] SUSPENDED (STATE: 160)

Thanks in advance.

Alidus answered 8/11, 2014 at 13:2 Comment(0)
C
1

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();
        }];
    });
  }
}
Cosetta answered 11/11, 2014 at 23:47 Comment(2)
I have the exact same issue. I tried your code @moonlight but isConnected is FALSE so nothing really happens.Automotive
Can you elaborate on your answer? I find that the willSuspendWithBlock doesn't get called before entering background but when coming back to foreground. It's really frustrating. Such a simple need to send a notification to a channel before going to background and I can't figure it out. Not really good for self estime :(Automotive
A
1

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.

Automotive answered 14/12, 2014 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.