iOS推送通知无法接收

时间:2017-09-06 14:47:05

标签: ios apple-push-notifications

这是我在AppDelegate中接收推送通知的代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        registerForPushNotifications(application: application)
        return true
    }

    func application(_ application: UIApplication,
                     didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let tokenParts = deviceToken.map { data -> String in
            return String(format: "%02.2hhx", data)
        }

        let token = tokenParts.joined()
        print("Device Token: \(token)")
    }

    func application(_ application: UIApplication,
                     didFailToRegisterForRemoteNotificationsWithError error: Error) {
        print("Failed to register: \(error)")
    }

    func registerForPushNotifications(application: UIApplication) {

        UNUserNotificationCenter.current().delegate = self
        UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert], completionHandler: {(granted, error) in
            if (granted)
            {
                UIApplication.shared.registerForRemoteNotifications()
            }
        })

    }

我在Time Profiler(cmd + I)中运行我的应用程序。应用程序收到令牌,然后我复制并在pushtry.com中使用。 pushtry说%“推送通知已成功发送”。但没有收到任何通知:(

我关注this tutorial

0 个答案:

没有答案