繁体   English   中英

在iOS中集成FCM进行推送通知时,是否使用了设备令牌?

[英]Is there any use of Device Token while integrating FCM for push notification in iOS?

我有以下情况

使用APNS

用于接收我的本机iOS应用程序的远程通知。 使用该证书时,我们需要创建.p12证书,并且需要发送在注册推送通知时在Appdelegate.m文件中生成的设备令牌。 因此,我们采用了将设备ID发送到后端的方法,以将通知发送到该特定设备。

使用FCM时

我通过了FCM,还得到了我们需要将.p12文件上传到他们的控制台。 到目前为止一切都很好。 但是当涉及到设备令牌部分时,我不清楚“设备令牌”的“刷新”过程。 firebase是否会生成设备令牌,还是需要设置在didRegisterforRemoteNotification中生成的设备令牌?

    import FirebaseMessaging

override func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  FIRApp.configure()

  NSNotificationCenter.defaultCenter().addObserver(self,
                                                   selector: #selector(tokenRefreshNotification(_:)),
                                                   name: kFIRInstanceIDTokenRefreshNotification,
                                                   object: nil)
}

// NOTE: Need to use this when swizzling is disabled
public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

  FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
}

func tokenRefreshNotification(notification: NSNotification) {
  // NOTE: It can be nil here
  let refreshedToken = FIRInstanceID.instanceID().token()
  print("InstanceID token: \(refreshedToken)")

  connectToFcm()
}

func connectToFcm() {
  FIRMessaging.messaging().connectWithCompletion { (error) in
    if (error != nil) {
      print("Unable to connect with FCM. \(error)")
    } else {
      print("Connected to FCM.")
    }
  }
}

public func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
  print(userInfo)
}

由于每火力地堡文档中的位置 ,它告诉:

在以下情况下,注册令牌可能会更改:

  1. 该应用已在新设备上还原

  2. 用户卸载/重新安装应用程序

  3. 用户清除应用程序数据。

并为“花哨的”。 这个概念是,如果禁用它,则必须重写didRegisterForRemoteNotificationsWithDeviceToken方法来检索APNs令牌,然后调用setAPNSToken 因为您已经在执行此操作。

以下是文档中有关启用/禁用方法混乱的内容 ,如下所示:

FCM提供的方法转换可简化您的客户端代码。 但是,对于不喜欢使用它的开发人员,FCM允许您通过在应用程序的Info.plist文件中添加FirebaseAppDelegateProxyEnabledflag并将其值设置为NO(布尔值)来禁用方法混乱。

FCM混乱影响您如何处理默认注册令牌以及如何处理下游消息回调。 在适用的情况下,本指南提供了启用和不启用方法转换的迁移示例。

希望对你清楚!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM