2014-09-02 135 views
0

當應用程序處於打開狀態時,我已經成功集成了Sinch SDK並且它的工作很好,現在我正在處理應用程序處於脫機狀態時的調用。iOS應用程序在使用APN離線時的Sinch調用

使用下面的方法,我可以看到推對,我將這個推對發送到服務器來推送。

- (void)call:(id<SINCall>)call shouldSendPushNotifications:(NSArray *) pushPairs { 

} 

在Appdelegate.m didFinishLaunchingWithOptions()方法中,我得到了sinch特定的有效負載。

NSDictionary* remotePush = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
    NSLog(@"%@",remotePush); 
    if (remotePush) { 
     NSLog(@"Entery ****"); 
     // Extract the Sinch-specific payload from the Apple Remote Push Notification 
     NSString* payload = [[remotePush valueForKey:@"aps"] valueForKey:@"SIN"]; 

    // [[userInfo valueForKey:@"aps"] valueForKey:@"content-available"]; 
     NSLog(@"Payload :%@",payload); 
     // Get previously initiated Sinch client 
     id<SINClient> client = _client; 
     NSLog(@"Client ID %@",[client userId]); 
     id<SINNotificationResult> result = [client relayRemotePushNotificationPayload:payload]; 
     NSLog(@"Result :%@",result); 
     if (result.isCall && result.callResult.isTimedOut) { 
      // Present alert notifying about missed call 
     } else if (!result.isValid) { 
      // Handle error 
     } 
    } 

下面是完整的推送通知的數據:

{ 
     aps =  { 
      SIN = "AgEBdeibxmJBSK2Y7Nh/fz50VMhVBVQMKzkxODg0NzE4MjQx"; 
      alert = ""; 
      "content-available" = 1; 
      type = 2; 
     }; 
    } 

來到這個代碼:

// Get previously initiated Sinch client 
    id<SINClient> client = _client; 
    NSLog(@"Client ID %@",[client userId]); 

當我打印客戶端ID是零,我需要怎麼去以前發起的Sinch客戶端?由於App關閉,客戶端實例被釋放。

回答

4

您需要自己堅持userId,然後在重新啓動應用程序時,使用userId對SinchClient進行初始化,您在上次關閉應用程序時堅持使用userId。

最簡單的方法是使用NSUserDefaults並保存用戶登錄時編寫的字段「userId」,如果用戶退出應用程序,則刪除該字段。

例如,在啓動時:

[[NSUserDefaults standardUserDefaults] setObject:userId forKey:@"userId"]; 

,然後當你的應用程序通過APN推出:

NSString *persistedUserId = [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"]; 
if (persistedUserId != nil) { 
    _client = [Sinch clientWithApplicationKey:APPLICATION_KEY 
          applicationSecret:APPLICATION_SECRET 
          environmentHost:ENVIRONMENT 
            userId:persistedUserId]; 
} 
+0

感謝迅速的回覆,我已經按照你做,現在我可以看到用戶ID,客戶端啓動,但呼叫不中繼。當我打印ID 結果= [客戶端RelayRemotePushNotificationPayload:有效載荷]; NSLog(@「Result:%@」,result); 結果:。仍然呼叫不中繼。 – krish 2014-09-02 07:29:47

+0

@krish我認爲這是一個單獨的問題,但請參閱http://stackoverflow.com/questions/25451427/sinch-calls-via-remote-notification-do-not-start,如果這可能是幫助 – frals 2014-09-02 08:06:48

相關問題