ios - 如何快速将 iPhone 设备注册令牌传递给 Web 服务?
问题描述
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
}
解决方案
//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.
推荐阅读
- java - Firestore google.cloud.Timestamp 解析
- javascript - Google Chrome 将 XHR 调用的状态显示为 (blocked:other)
- java - 如何使用多个变量执行 MyBatis 查询
- python - 如何在python中将html代码作为变量返回
- npm - 如何为自己的 npm 注册表配置保存前缀
- excel - 如何在已保存的电子邮件文件夹中搜索字符串
- go - 使用 streadway 库处理多个队列的通用方法
- c# - 使用 decimal.Parse 无法正确显示十进制值
- xamarin - 在 UICollectionView GetCell 中设置 translucent true 返回错误的 indexPath
- javascript - Javascript - 切换类问题