firebase iOS没有收到推送通知 [英] firebase iOS not receive push notifications

查看:586
本文介绍了firebase iOS没有收到推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中包括谷歌firebase - 创建谷歌帐户,创建谷歌应用程序,上传APNS证书(.pem和在另一项服务工作),并从控制台发送推送通知,我的应用程序不会收到它。在Firebase控制台中,我看到状态已完成,但大致设备数量为 - 。

当然,我更新了配置文件和APNS证书

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

//注册远程通知
if #available(iOS 8.0,*){
设置:UIUserNotificationSettings =
UIUserNotificationSettings(forTypes:[.Alert ,.badge,.Sound],类别:nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
//后退
let类型:UIRemoteNotificationType = [.Alert,.Badge,.Sound]
application.registerForRemoteNotificationTypes(types)
}


FIRApp.configure()
NSNotificationCenter.defaultCenter()。addObserver(self,selector:#selector(self.tokenRefreshNotificaiton),
name:kFIRInstanceIDTokenRefreshNotification,object:nil)

$ b $ func application(application: UIApplication,didReceiveRemoteNotification userInfo:[NSObject:AnyObject],
fetchCompletionHandler completionHandler:(UIBackgroundFetchResult) - > (void){

print(userInfo)
}

func tokenRefreshNotificaiton(notification:NSNotification){
if refreshedToken = FIRInstanceID.instanceID() token(){
print(InstanceID token:\(refreshedToken))

User.sharedUser.googleUID = refreshedToken
}
}


func application(application:UIApplication,handleActionWithIdentifier identifier:String ?, forRemoteNotification userInfo:[NSObject:AnyObject],withResponseInfo responseInfo:[NSObject:AnyObject],completionHandler:(> Void){

print(userInfo)


func application(application:UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken:NSData){

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

func application(application:UIApplication,handleActionWithIdentifier identifier:String ?, forRemoteNotification u serInfo:[NSObject:AnyObject],withResponseInfo responseInfo:[NSObject:AnyObject],completionHandler:() - > Void){
$ b $ print(userInfo)
}

func application(application:UIApplication,didReceiveRemoteNotification userInfo:[NSObject:AnyObject],
fetchCompletionHandler completionHandler :(UIBackgroundFetchResult) - > Void){


print(userInfo)
}

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

print(ошибка)
print(error)
print(error.description)


FIRMessaging
。尝试添加到你的 AppDelegate

$ p $ func applicationDidBecomeActive(application:UIApplication ){
FIRMessaging.messaging()。connectWithCompletion {
print(error)
}
}


I include google firebase in my app - create google account, create google app, upload APNS certifications (.pem and in work in another service), and send push notifications from console, and my app not receive it. In Firebase console i see status complete but Approximate number of devices is "-"

Of course I updated provisions profiles and APNS cert

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

    // Register for remote notifications
    if #available(iOS 8.0, *) {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    } else {
        // Fallback
        let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
        application.registerForRemoteNotificationTypes(types)
    }


    FIRApp.configure()
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotificaiton),
                                                     name: kFIRInstanceIDTokenRefreshNotification, object: nil)
}      

 func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
                 fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

    print(userInfo)
}

func tokenRefreshNotificaiton(notification: NSNotification) {
    if let refreshedToken = FIRInstanceID.instanceID().token() {
        print("InstanceID token: \(refreshedToken)")

        User.sharedUser.googleUID = refreshedToken
    }
}


func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {

    print(userInfo)
}

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

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

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {

    print(userInfo)
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
                 fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {


    print(userInfo)
}

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

    print("ошибка")
    print(error)
    print(error.description)

}

解决方案

The first thing I see is there's no call to connect to FIRMessaging. Try adding this to your AppDelegate:

func applicationDidBecomeActive(application: UIApplication) {
    FIRMessaging.messaging().connectWithCompletion { error in
        print(error)
    }
}

这篇关于firebase iOS没有收到推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆