推送器:手机未收到iOS推送通知



我正在尝试使用Pusher为我的应用程序发送推送通知。

我正在学习他们的教程(https://pusher.com/tutorials/push-notifications-ios/)设置它。到目前为止,我已经在XCode中启用了Push Notifications,创建了一个实例并复制了它们的代码片段。

这是我的AppDelegate.swift文件(只包括相关部分(:

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
let pushNotifications = PushNotifications.shared
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.pushNotifications.start(instanceId: [instanceId)
self.pushNotifications.registerForRemoteNotifications()
try? self.pushNotifications.addDeviceInterest(interest: "hello")
return true
}

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
self.pushNotifications.registerDeviceToken(deviceToken)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
self.pushNotifications.handleNotification(userInfo: userInfo)
}
}

我正在发送带有命令的推送通知

curl -H "Content-Type: application/json" 
-H "Authorization: Bearer $SECRET_KEY" 
-X POST "https://INSTANCE_ID.pushnotifications.pusher.com/publish_api/v1/instances/INSTANCE_ID/publishes" 
-d '{"interests":["hello"],"apns":{"aps":{"alert":{"title":"Hello","body":"Hello, world!"}}}}'

执行curl命令后,我得到以下消息:

{"publishId":[publishId]}

然而,iPhone上没有显示我正在测试的通知。该应用程序正在后台运行。有什么帮助吗?

谢谢。

首先交叉检查链接中提到的所有点:https://developer.apple.com/library/archive/technotes/tn2265/_index.html

确保您的apns证书有效,并且您已经在XCODE中为推送通知设置了适当的功能

如果配置了发布证书,那么只有发布应用程序才能接收推送。

  1. 配置证书和代码,plist。。。

  2. XCode->产品->疼痛->释放上传.ipa.

  3. 在testfight中安装应用程序,然后推送并接收通知

最新更新