ios - Pusher:iOS 推送通知未到达手机
问题描述
我正在尝试使用 Pusher 为我的应用程序发送推送通知。
我正在按照他们的教程(https://pusher.com/tutorials/push-notifications-ios/)进行设置。到目前为止,我已经在 XCode 中启用了推送通知,创建了一个实例并复制了它们的代码片段。
这是我的 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 上没有显示任何通知。该应用程序正在后台运行。有什么帮助吗?
谢谢。
解决方案
确保您的 apns 证书有效,并且您已在 XCODE 中为推送通知设置了适当的功能
推荐阅读
- dc.js - 条形图显示线条(细条)而不是条 [已解决]
- java - 如何在 Android 内部保存流式传感器数据?
- java - 如何使用 Spring Integration 在 IntegrationFlow 链中通过 SFTP 上传文件?
- python - 在 Windows 上,导入 CV2 时 DLL 加载失败:找不到指定的模块
- python - 部署 Django 应用程序(Apache、Passenger、Virtualenv)
- django - Django:如何在不刷新页面的情况下在提交第一个表单时显示第二个表单?
- neo4j - MLM 图的递归密码查询
- swift - 如何修复UIKit中从底部切割的字体?
- c# - 我的播放器预制件向前移动,直到它撞到一个物体,这是怎么回事?
- python - 张量什么时候输出一个值,什么时候输出一个张量对象?