Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 调用了didRegisterForRemoteNotificationsWithDeviceToken,但未发送推送通知_Ios_Firebase_Swift3_Apple Push Notifications_Firebase Cloud Messaging - Fatal编程技术网

Ios 调用了didRegisterForRemoteNotificationsWithDeviceToken,但未发送推送通知

Ios 调用了didRegisterForRemoteNotificationsWithDeviceToken,但未发送推送通知,ios,firebase,swift3,apple-push-notifications,firebase-cloud-messaging,Ios,Firebase,Swift3,Apple Push Notifications,Firebase Cloud Messaging,我正在尝试在iOS中实现推送通知。我曾经成功地使它工作过一次。但现在我面临一个奇怪的问题。我已经退出XCode并重新打开它,没有任何代码被更改,我仍然得到deviceToken,但现在我的设备上没有收到任何推送通知。我也在使用Firebase来获取通知,它也工作得很好,但现在它给了我空白字符串作为设备令牌 在AppDelegate中,我使用以下代码: if #available(iOS 10.0, *) { // For iOS 10 display notificati

我正在尝试在iOS中实现推送通知。我曾经成功地使它工作过一次。但现在我面临一个奇怪的问题。我已经退出XCode并重新打开它,没有任何代码被更改,我仍然得到deviceToken,但现在我的设备上没有收到任何推送通知。我也在使用Firebase来获取通知,它也工作得很好,但现在它给了我空白字符串作为设备令牌

在AppDelegate中,我使用以下代码:

    if #available(iOS 10.0, *) {
        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self

        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()

//This is triggered and I am getting the push notification token but using this instead of firebase token to send directly via APNS is also not working.
public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().setAPNSToken(deviceToken, type: .sandbox)
}

//This is triggered but the token here is a blank string
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
    Messaging.messaging().subscribe(toTopic: "ios_topic")
}

在我退出XCode之前,它一直在工作,但在没有任何代码更改的情况下,它突然停止了工作。我尝试了一切,包括重新启动系统。有时,在新安装过程中,会两次调用<代码>didRegisterForRemoteNotificationsWithDeviceToken,一次在我授予权限之前,一次在授予权限之后。可能是因为设备令牌现在被解析为“32字节”

请参阅此处的更多信息: