【发布时间】:2018-01-06 18:46:44
【问题描述】:
我正在开发一个使用 CallKit 通知用户的应用程序。但是,我正在使用 APN 测试应用程序,但它没有按预期工作。
流程应该是: 接收 FCM -> 使用 Callkit 创建呼叫 -> 用户接受呼叫 -> 做某事。
流程与 WHATSAPP 之类的应用类似,但我没有 VOIP,我只需要确保每次有 FCM 时都激活 CALLKIT。
但是,目前,如果应用程序处于后台或非活动状态,则 callkit 将不会启动。
我正在考虑使用 PushKit 来实现它。但是,我没有使用 PushKit 的经验(不确定我的应用是否会被禁止,根据这篇文章:PushKit: Can we use push kit(VoiP Push) in Chat Application without using VoiP
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
let aps = userInfo["aps"] as! [String: AnyObject]
// 1
if aps["content-available"] as? Bool == true {
let uuid = UUID(uuidString: MyVariables.uuid)
AppDelegate.shared.displayIncomingCall(uuid: uuid!, handle: "Sanoste", hasVideo: false) { _ in}
}else {
completionHandler(UIBackgroundFetchResult.newData)
}
// Print full message.
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
上面的代码是我现在用于 CallKit 的代码。
【问题讨论】:
标签: ios swift firebase firebase-cloud-messaging callkit