【问题标题】:Pusher: iOS Push Notification not arriving on phonePusher:iOS 推送通知未到达手机
【发布时间】:2021-09-20 01:45:19
【问题描述】:

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

我正在按照他们的教程 (https://pusher.com/tutorials/push-notifications-ios/) 进行设置。到目前为止,我已经在 XCode 中启用了推送通知,创建了一个实例并复制了他们的代码 sn-p。

这是我的 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 上没有显示任何通知。该应用程序正在后台运行。有什么帮助吗?

谢谢。

【问题讨论】:

  • 当应用在前台时,通知是否显示在 iPhone 上?
  • 不,不是。它说它已在终端中发布(因此为 publishId),但从未出现在我的 iPhone 上。
  • @DarrelGulseth 要获得更快的解决方案,请分享具有相同代码设置的示例应用程序的 Github 链接。

标签: ios swift push-notification apple-push-notifications pusher


【解决方案1】:

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

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

  2. XCode->Product->Achive->Release...,上传.ipa。

  3. 在testfight中安装应用,然后推送和接收通知。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-08
        • 2014-01-19
        • 2018-01-12
        • 1970-01-01
        • 2022-11-30
        • 1970-01-01
        相关资源
        最近更新 更多