Как передать токен регистрации устройства iPhone на веб-сервис в swift? - PullRequest
0 голосов
/ 30 апреля 2018
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        UIApplication.shared.statusBarView?.backgroundColor = UIColor(red:160/255, green:206/255, blue:78/255, alpha: 1)
        // Override point for customization after application launch.

        FirebaseApp.configure()

        Messaging.messaging().delegate = self

        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()

        let token = Messaging.messaging().fcmToken
        print("FCM token: \(token ?? "")")

        NotificationCenter.default.addObserver(self, selector: #selector(tokenRefreshNotification), name:nil, object: nil)

        return true

    }

1 Ответ

0 голосов
/ 30 апреля 2018
//Below method also return FCM token and Passed with your WS
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
      print("Firebase registration token: \(fcmToken)")

      // Passed TOKEN with your web service

    } 

    print("FCM token: \(token ?? "")") - It's Return value of Tokena and Passed with your Websevice. 
...