我正在使用Sinch并将Firebase用作数据库,并使用其云功能发送通知。发送通知工作正常,但是shouldSendPushNotifications
函数却没有被调用,因此我无法将sinch有效负载添加到通知数据中,并且我在互联网上找不到任何可靠的工作示例,因此我放弃了然后决定将SINcall
对象发送到数据库,被调用者将检索它并回答。
但是问题是Firebase仅存储字符串,因此当我检索存储的SINCall时会收到错误Could not cast value of type '__NSCFString' (0x102096998) to '__ObjC.SINCall' (0x10209ab08)
。那么有没有办法将其转换为SINCall,以便我可以接听,拒绝等?
编辑:
这是我在AppDelegate.swift
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("USERINFO: \(userInfo["sin"]!)") <-- prints call: <SINCallImpl: 0x1c00f2600>
let incomingCall = userInfo["sin"]!
SINClientManager.shared.call = incomingCall as! SINCall <-- Error occurs
...
}
答案 0 :(得分:0)
您需要将数据发送到Sinch客户端以建立呼叫,您无法将字符串转换为呼叫。
NSString* payload = [remotePush objectForKey:@"SIN"];
// Get previously initiated Sinch client
id<SINClient> client = [self sinchClient];
id<SINNotificationResult> result = [client relayRemotePushNotificationPayload:payload];
if (result.isCall && result.callResult.isTimedOut) {
// Present alert notifying about missed call
} else if (!result.isValid) {
// Handle error
}