2014-09-02 70 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

相关问题