applicationDidEnterBackground

applicationDidEnterBackground

我正在将PubNub用于IOS应用程序(IOS SDK 8.0)。当我尝试从“applicationDidEnterBackground”事件中的频道退订时,得到以下控制台输出。它说该频道已取消订阅,但是当我从管理控制台检查时,我仍在该频道上。您能对此提供一些建议吗?

这是我在“applicationDidEnterBackground”中使用的行:

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

这是“applicationDidEnterBackground”事件之后的PubNub控制台输出:
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)

提前致谢。

最佳答案

好吧,如果您的应用程序不能持久地在后台运行,那么当应用程序转移到后台执行状态时,您将无法调用此类命令。
您可以尝试使用此回调执行一些请求,然后再将PubNub客户端与您的应用一起挂起:

- (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();
        }];
    });
  }
}

07-27 13:40