我正在尝试使用FCM通知.
但是< FIRInstanceID / WARNING>无法获取APNS令牌错误Domain = com.firebase.iid代码= 1001“(null)”发生,所以我无法获得通知.
有什么问题?

在控制台,
无法获取APNS令牌错误Domain = com.firebase.iid代码= 1001“(null)”

以下是我的App Applegate代码

import UIKit
import CoreData
import Alamofire
import Firebase
import FirebaseInstanceID
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder,UIApplicationDelegate {

    var window: UIWindow?

    var badgeCount : Int = 0;

    enum BasicValidity : String {
        case Success = "basicInfo"
        case Fail = "OauthAuthentificationError"
    }

    func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.


        let uns: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert,.Badge,.sound],categories: nil)
        application.registerUserNotificationSettings(uns)
        application.registerForRemoteNotifications()

        FIRApp.configure()

        NSNotificationCenter.defaultCenter().addobserver(self,selector: #selector(self.tokenRefreshNotification),name: kFIRInstanceIDTokenRefreshNotification,object: nil)

        if let token = FIRInstanceID.instanceID().token() {
            sendTokenToServer(token)
            print("token is < \(token) >:")
        }

        return true
    }

    func application(application: UIApplication,didRegisterForRemoteNotificationsWithDevicetoken devicetoken: NSData){


        print("didRegisterForRemoteNotificationsWithDevicetoken()")

        // if FirebaseAppDelegateProxyEnabled === NO:
        FIRInstanceID.instanceID().setAPNSToken(devicetoken,type: .SandBox)

        print("APNS: <\(devicetoken)>")
    }

    func application(application: UIApplication,didFailToRegisterForRemoteNotificationsWithError error: NSError){

         print("Registration for remote notification Failed with error: \(error.localizedDescription)")
    }

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


        print("didReceiveRemoteNotification()")

        //if FirebaseAppDelegateProxyEnabled === NO:
        FIRMessaging.messaging().appDidReceiveMessage(userInfo)

       // handler(.NoData)

    }

    // [START refresh_token]
    func tokenRefreshNotification(notification: NSNotification) {
        print("tokenRefreshNotification()")
        if let token = FIRInstanceID.instanceID().token() {
            print("InstanceID token: \(token)")
            sendTokenToServer(token)
            FIRMessaging.messaging().subscribetoTopic("/topics/global")
            print("Subscribed to: /topics/global")
        }
        connectToFcm()
    }
    // [END refresh_token]

    func sendTokenToServer(currentToken: String) {
        print("sendTokenToServer() Token: \(currentToken)")
        // Send token to server ONLY IF NECESSARY
    }

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

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks,disable timers,and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    // [START disconnect_from_fcm]
    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources,save user data,invalidate timers,and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution,this method is called instead of applicationWillTerminate: when the user quits.

        FIRMessaging.messaging().disconnect()
        print("disconnected from FCM.")
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was prevIoUsly in the background,optionally refresh the user interface.

       // UIApplication.sharedApplication().applicationIconBadgeNumber = 0
         connectToFcm()

    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
        // Saves changes in the application's managed object context before the application terminates.
        self.saveContext()
    }

>如果我通过使用软件包ID发送通知,我可以从Firebase控制台获取通知.但是如果我们的服务器通过令牌将通知发送到特定设备,我无法得到.

解决方法

对我而言,我尝试了以下thigs来使其工作:

>重新启用功能 – >推送通知,钥匙串共享和后台模式 – >远程通知
>重新安装应用程序(这将生成新的刷新令牌,对于后续运行将是一样的,因此每次运行应用程序时都不会打印).
>确保我在firebase console->项目设置 – >云消息中上传了正确的.p12文件
>重新检查苹果开发人员中心的配置文件(我必须重新启动ios开发人员配置配置文件.)

您可能仍然会收到警告,但是如果您尝试使用刷新令牌从firebase控制台发送通知,它将会工作.

ios – Firebase(FCM)无法获取APNS令牌错误Domain = com.firebase.iid代码= 1001的更多相关文章

  1. 设备注册推送通知后iOS获取设备令牌?

    编辑–我知道所有设备都在线,临时配置文件链接到应用程序ID,因为我可以接收推送通知.接收推送通知不是问题–获取设备令牌并将其存储在Parse中是我想要实现的.谢谢解决方法嗯,请再次尝试检查您的配置文件.听起来你可能正在使用带有通配符的一个.您可能正在接收来自服务器的推送,因为您最初使用正确的配置文件进行部署,但是如果您已更改为使用通配符配置文件,则您将无法正确注册远程通知…

  2. ios – 获得APNs响应BadDeviceToken或Unregistered的可能原因是什么?

    我知道设备令牌在某些时候是有效的.用户如何使其设备令牌变坏?从关于“未注册”的文档:Thedevicetokenisinactiveforthespecifiedtopic.这是否意味着应用程序已被删除?.您应该看到四种分发方法:如果您选择AppStore或Enterprise,您将在后面的对话框中看到Xcode将APNS权利更改为生产:如果选择AdHoc或Development,则aps-environment下的文本将是开发,然后应与后端的配置匹配.

  3. ios – NSUbiquityIdentityDidChangeNotification和SIGKILL

    当应用程序被发送到后台时,我们会删除观察者吗?我遇到的问题是,当UbiquityToken发生变化时,应用程序终止,因为用户已经更改了iCloud设置.你们如何设法订阅这个通知,如果你不这样做,你会做什么来跟踪当前登录的iCloud用户?

  4. 本地通知无法在iOS 11中运行

    我在我的应用中使用本地通知.现在iOS11已经出现了,他们不再工作了.我没有在发布文档中看到任何可能导致此问题的内容,是否有人知道可能导致此问题的原因?我知道它已被弃用,但我认为没有理由说它为什么不应该只是工作.提前致谢解决方法似乎iOS11中存在一个错误.我可以看到我是否安排了超过64个允许的通知,它忽略了我安排的所有通知.docs状态系统保持最快的64个通知并丢弃其余的通知.在iOS11上它只是丢弃所有…

  5. ios – XMPP应用终止而不是回复消息

    我在XMPP应用程序中工作.当我终止并杀死我的应用程序时,1)XMPP服务器中未连接用户.用户离线.但我希望用户连接和在线.喜欢WhatsApp(应用).2)我当时无法从XMPP服务器端获取任何消息,这种方法不是调用.那么,我如何获得消息?

  6. 如何使用Firebase在iOS上验证用户的电子邮件地址?

    我坚持使用firebase进行电子邮件验证.我四处寻找指导但没有帮助.在用户验证他的电子邮件后,我的代码仍然打印出用户尚未验证.我还在尝试习惯firebase的语法.这是我的代码:这是我注册部分的代码:解决方法您在签名之前检查了用户电子邮件是否已经过验证.这对我有用.

  7. ios – 检测用户点击本地通知

    我会定期显示这样的本地通知.我需要检测回来的通知,我打算在这里写.无论用户点击通知还是自动在前台呼叫,它总是调用该功能.所以,我分开使用它.当我显示通知中心时,它变为InActive.但是,它仍然调用didReceivelocalnotification.我无法区分用户是否点击通知中心的通知或是因为我的定期发布通知.我怎么才能真正知道我在didReceivelocalnotification中点击

  8. 如何使用iOS SDK保存LinkedIn访问令牌?

    我在我的iOS应用程序中使用LinkedIn.我想保存访问令牌以供将来使用.令牌属于非属性类型,无法直接保存在NSUserDefaults中.我尝试使用NSKeyedArchiver,但我得到了输出:令牌中的文本即将到来,但值将为空.代码段1:我也尝试像这样保存,但结果是一样的:代码段2:我的编码或访问令牌有什么问题需要一些特殊技术来保存吗?请建议.解决方法这就是我拯救的方式.它对我有用.希望它有所帮助以这种方式使用保存的responseBody我希望这次我很清楚

  9. ios – 我可以在AppDelegate.m之外注册推送通知吗?

    我的应用程序能够成功注册推送通知,但我想将弹出警报移动到应用程序的其他区域如果我将AppDelegate.m中的相同代码实现到我的应用程序的另一个屏幕Other.m,它永远不会注册:如果我在AppDelegate.m中启用didRegisterForRemoteNotificationsWithDevicetoken,则从我的Other.m调用该方法的AppDelegate.m实例,但这不是我想要

  10. ios – 1天后firebase crashlytics报告中没有数据

    解决方法对于那些仍然有问题的人.检查您的podfile中是否还有pod’Firebase/Crash’.当我删除旧的Firebase崩溃报告时,我的问题已修复.

随机推荐

  1. iOS实现拖拽View跟随手指浮动效果

    这篇文章主要为大家详细介绍了iOS实现拖拽View跟随手指浮动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  2. iOS – genstrings:无法连接到输出目录en.lproj

    使用我桌面上的项目文件夹,我启动终端输入:cd然后将我的项目文件夹拖到终端,它给了我路径.然后我将这行代码粘贴到终端中找.-name*.m|xargsgenstrings-oen.lproj我在终端中收到此错误消息:genstrings:无法连接到输出目录en.lproj它多次打印这行,然后说我的项目是一个目录的路径?没有.strings文件.对我做错了什么的想法?

  3. iOS 7 UIButtonBarItem图像没有色调

    如何确保按钮图标采用全局色调?解决方法只是想将其转换为根注释,以便为“回答”复选标记提供更好的上下文,并提供更好的格式.我能想出这个!

  4. ios – 在自定义相机层的AVFoundation中自动对焦和自动曝光

    为AVFoundation定制图层相机创建精确的自动对焦和曝光的最佳方法是什么?

  5. ios – Xcode找不到Alamofire,错误:没有这样的模块’Alamofire’

    我正在尝试按照github(https://github.com/Alamofire/Alamofire#cocoapods)指令将Alamofire包含在我的Swift项目中.我创建了一个新项目,导航到项目目录并运行此命令sudogeminstallcocoapods.然后我面临以下错误:搜索后我设法通过运行此命令安装cocoapodssudogeminstall-n/usr/local/bin

  6. ios – 在没有iPhone6s或更新的情况下测试ARKit

    我在决定下载Xcode9之前.我想玩新的框架–ARKit.我知道要用ARKit运行app我需要一个带有A9芯片或更新版本的设备.不幸的是我有一个较旧的.我的问题是已经下载了新Xcode的人.在我的情况下有可能运行ARKit应用程序吗?那个或其他任何模拟器?任何想法或我将不得不购买新设备?解决方法任何iOS11设备都可以使用ARKit,但是具有高质量AR体验的全球跟踪功能需要使用A9或更高版本处理器的设备.使用iOS11测试版更新您的设备是必要的.

  7. 将iOS应用移植到Android

    我们制作了一个具有2000个目标c类的退出大型iOS应用程序.我想知道有一个最佳实践指南将其移植到Android?此外,由于我们的应用程序大量使用UINavigation和UIView控制器,我想知道在Android上有类似的模型和实现.谢谢到目前为止,guenter解决方法老实说,我认为你正在计划的只是制作难以维护的糟糕代码.我意识到这听起来像很多工作,但从长远来看它会更容易,我只是将应用程序的概念“移植”到android并从头开始编写.

  8. ios – 在Swift中覆盖Objective C类方法

    我是Swift的初学者,我正在尝试在Swift项目中使用JSONModel.我想从JSONModel覆盖方法keyMapper,但我没有找到如何覆盖模型类中的Objective-C类方法.该方法的签名是:我怎样才能做到这一点?解决方法您可以像覆盖实例方法一样执行此操作,但使用class关键字除外:

  9. ios – 在WKWebView中获取链接URL

    我想在WKWebView中获取tapped链接的url.链接采用自定义格式,可触发应用中的某些操作.例如HTTP://我的网站/帮助#深层链接对讲.我这样使用KVO:这在第一次点击链接时效果很好.但是,如果我连续两次点击相同的链接,它将不报告链接点击.是否有解决方法来解决这个问题,以便我可以检测每个点击并获取链接?任何关于这个的指针都会很棒!解决方法像这样更改addobserver在observeValue函数中,您可以获得两个值

  10. ios – 在Swift的UIView中找到UILabel

    我正在尝试在我的UIViewControllers的超级视图中找到我的UILabels.这是我的代码:这是在Objective-C中推荐的方式,但是在Swift中我只得到UIViews和CALayer.我肯定在提供给这个方法的视图中有UILabel.我错过了什么?我的UIViewController中的调用:解决方法使用函数式编程概念可以更轻松地实现这一目标.

返回
顶部