gpt4 book ai didi

IOS Sinch Calling when Application is offline using APN(Get previously initiated Client)

转载 作者:行者123 更新时间:2023-11-28 19:01:04 24 4
gpt4 key购买 nike

我已经成功集成了 Sinch SDK,它在应用程序打开时运行良好,现在我可以在我的应用程序离线时处理调用。

使用下面的方法我可以看到推送对,我正在将这个推送对发送到服务器以传递推送。

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

}

在 Appdelegate.m didFinishLaunchingWithOptions () 方法中,我正在获取特定的负载。

 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 客户端?由于应用程序关闭,客户端实例被释放。

最佳答案

您需要自己保留 userId,然后在应用重新启动时,使用您在上次应用关闭时保留的 userId 初始化一个 SinchClient

最简单的可能是使用 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];
}

关于IOS Sinch Calling when Application is offline using APN(Get previously initiated Client),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25616844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com