我已经成功集成了 Sinch SDK,并且它在应用程序打开时工作得很好,现在我正在处理我的应用程序离线时的呼叫。
使用下面的方法,我可以看到推送对,我正在将此推送对发送到服务器以传递推送。
- (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 为 Nil 时,我需要如何获取先前启动的 Sinch 客户端?由于 App 关闭,客户端实例被释放。