【发布时间】:2017-07-31 02:08:35
【问题描述】:
我有一个自定义通知服务可以成功发送通知,但是当用户点击通知时,didReceiveRemoteNotification 永远不会被调用。该应用程序将打开到最后一个状态,我正在尝试深度链接到应用程序中的特定场景。
在我的 didFinishLaunchingWithOptions 中,我正在注册通知类型 通过调用这个函数”
func registerForPushNotifications(应用程序:UIApplication){ 让 notificationSettings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil) UIApplication.shared.registerUserNotificationSettings(notificationSettings) }
我正在将我的设备注册到后端服务并调用 didRegisterForRemoteNotificationsWithDeviceToken 函数
接下来我有我的 didregister 函数
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { UIApplication.shared.registerForRemoteNotifications() }
最后,我得到了 didReceiveRemoteNotification,我希望在点击通知时调用它。
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { }
发布到我的后端服务的 xml 相当简单,似乎按预期工作: { “观众”:{ “ios_channel”:“e06b9r8r-ffce-4fa6-92ec-123456789” }, “通知”:{ “ios”:{ "alert":"测试声音发送", "title":"测试警报", “声音”:“默认” } }, “设备类型”:[ “ios” ] }
如果有人对为什么不调用 didReceiveRemoteNotification 函数有意见,我们将不胜感激。
【问题讨论】:
-
我在发布后不久就解决了这个问题。我正在使用 Urban Airship v1.0,UA 库将自动集成到应用程序中,该应用程序拦截任何返回到应用程序的调用。要解决此问题,请在 AirshipConfig.plist 文件或 UAConfig 中将“automaticSetupEnabled”添加到 NO。 UA 在这里解释了这一变化:docs.urbanairship.com/platform/ios.html#automatic-integration