GCM IOS NotRegistered 问题 [英] GCM IOS NotRegistered issue

查看:18
本文介绍了GCM IOS NotRegistered 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 GCM 已经很长时间了.一天突然断了.问题是我发送的第一个推送我得到了成功状态,但该应用程序没有收到任何推送.我发送的第二次推送失败并出现 NotRegistered 错误.我重新安装了应用程序:成功(未收到通知)、失败(未注册)-> 循环.不知道有什么变化谷歌支持非常没有帮助,并且花费了大量时间来回答简单的问题,无论是 GCM 问题、APN 问题还是客户端问题.如果有人以前遇到过这样的问题,请告诉我要查找的内容.这就是它的样子:

我怀疑它是在更新到 iOS 9 后发生的.不过我不确定.如果新 iOS 中的某些内容可能会阻止 GCM,如果有人指出,我将不胜感激.

更新:

解决方案

于是我解决了这个问题.看来我没有使用正确的 iOS 开发配置文件.我使用的是通用的,而我需要为我的包名称使用特定的.它发生的原因是因为我一周前重新安装了我的操作系统,所以另一个证书被清除了并且在我下载并手动将它添加到 Xcode 之前不起作用.我还需要从设备中删除团队配置文件.完全不是 GCM 或 APNs 错误.

I've been using GCM just fine for a long time already. One day it suddenly broke. The problem is that the first push I send I get success status back but the app doesn't receive any push whatsoever. The second push I send gets failure with an NotRegistered error. I reinstall the app: success(no notification received), failure(NotRegistered) -> Loop. I don't know what's changed. Google support is being very unhelpful and is taking a lot of time answering simple question whether it is GCM problem, APNs problem or client problem. If anyone had such issue before, please let me know what to look for. That is how it looks like:

I suspect that it happened after updating to iOS 9. I'm not sure though. If there are things in new iOS that might be blocking GCM I would appreciate if somebody pointed it out.

UPDATE:

GCM push fails with NotRegistered

that guy had a similar problem. The issue was with some manifest file. Could there be some entries in the Info.plist that I need to add for iOS 9 to allow GCM ?

UPDATE:

onTokenRefresh is being called every time the app launches. I'm getting the same token back, though. So there is a problem with a token on a GCM server, I suspect.

GCM DELEGATE CODE IN APPDELEGATE:

var connectedToGCM = false


private var deviceToken: NSData?

var gcmSenderID: String!
let authorizedEntity = "my GCM Sender_ID"


public func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    var configureError:NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: (configureError)")
    gcmSenderID = GGLContext.sharedInstance().configuration.gcmSenderID
    // [END_EXCLUDE]
    // 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)
    }

    // [END register_for_remote_notifications]
    // [START start_gcm_service]
    let gcmConfig = GCMConfig.defaultConfig()
    GCMService.sharedInstance().startWithConfig(gcmConfig)

    return true
}

public func onTokenRefresh() {
    print("Token needs to be refreshed!")
    let options = [
        kGGLInstanceIDRegisterAPNSOption : deviceToken!,
        kGGLInstanceIDAPNSServerTypeSandboxOption : true
    ]
           GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(authorizedEntity, scope: kGGLInstanceIDScopeGCM, options: options) { (token, error) -> Void in
        if error != nil {
            print("Error: (error.localizedDescription)")
        } else {
            print("Token: (token)")
        }
    }
}


public func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let instanceIDConfig = GGLInstanceIDConfig.defaultConfig()
    instanceIDConfig.delegate = self
    // Start the GGLInstanceID shared instance with that config and request a registration
    // token to enable reception of notifications
    GGLInstanceID.sharedInstance().startWithConfig(instanceIDConfig)
    self.deviceToken = deviceToken
}

public func applicationDidEnterBackground(application: UIApplication) {
    GCMService.sharedInstance().disconnect()
    connectedToGCM = false
}

public func applicationDidBecomeActive( application: UIApplication) {
    print("App became active")
    UIApplication.sharedApplication().applicationIconBadgeNumber = 0
    // Connect to the GCM server to receive non-APNS notifications
    GCMService.sharedInstance().connectWithHandler({
        (NSError error) -> Void in
        if error != nil {
            print("Could not connect to GCM: (error.localizedDescription)")
        } else {
            self.connectedToGCM = true
            print("Connected to GCM")
            // ...
        }
    })
}

public func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    print("Notification received: (userInfo)")
    GCMService.sharedInstance().appDidReceiveMessage(userInfo)
}

public func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    print("Error registering")
}

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

        print("Notification received(background): (userInfo)")

        NotificationManager.sharedInsteance().parseNotification(userInfo)

        // This works only if the app started the GCM service
        GCMService.sharedInstance().appDidReceiveMessage(userInfo);

        // Handle the received message
        // Invoke the completion handler passing the appropriate UIBackgroundFetchResult value
        // [START_EXCLUDE]
        handler(UIBackgroundFetchResult.NewData);
        // [END_EXCLUDE]
}

UPDATE

OK, so I believe I messed up with .plist location (it wasn't in the root for some reason). I moved to the root and now I'm getting this warning/error when starting GCM:

UPD. Okay, it actually happened only once and stopped. So I don't think the problem is here.

After I moved .plist to the root directory onTokenRefresh() calls stopped, but I'm still getting NotRegistered.

解决方案

So I solved the problem. It appeared that I was not using the right iOS Development Provisioning Profile. I was using a generic one, while I needed to use a specific one for my bundle name. The reason it happened was because I reinstalled my OS a week ago or so, so the other certificate was wiped out and didn't work until I downloaded and manually added it to Xcode. I also needed to delete the team provisioning profile from the device as well. Totally not GCM or APNs fault.

这篇关于GCM IOS NotRegistered 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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