菜鸟教程小白 发表于 2022-12-12 12:34:56

ios - 已退订 channel ,仍在 channel 中


                                            <p><p>我将 PubNub 用于 IOS 应用程序(IOS SDK 8.0)。当我尝试取消订阅有关“applicationDidEnterBackground”事件的 channel 时,我得到以下控制台输出。它说 channel 已取消订阅,但是当我从管理控制台检查时,我仍在 channel 上。可以给点建议吗?</p>

<p>这是我在“applicationDidEnterBackground”中使用的行:</p>

<pre><code>PubNub.unsubscribeFromChannel(channelToReceive,{(list, err:PNError!)-&gt; Void in
      if(err != nil){
            println(err.localizedFailureReason)
      } else {
            println(&#34;Unsubscribed...&#34;)
      }
    })
</code></pre>

<p>这是“applicationDidEnterBackground”事件后的 PubNub 控制台输出:</p>

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

<p>提前致谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>好吧,如果您的应用程序不能在后台持久运行,那么当应用程序转移到后台执行状态时,您就不能调用此类命令。
您可以尝试使用此回调执行一些请求,然后 PubNub 客户端将与您的应用程序一起暂停:</p>

<pre><code>- (void)pubnubClient:(PubNub *)client willSuspendWithBlock:(void(^)(void(^)(void(^)(void))))preSuspensionBlock {

    if () {

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

            // Do last calls here
            // Always call this block as soon as required amount of tasks completed.
            completionBlock();
      }];
    });
}
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 已退订 channel ,仍在 channel 中,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/26817421/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/26817421/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 已退订 channel ,仍在 channel 中