当前位置: 首页 > 面试题库 >

GCM IOS未注册问题

柴英光
2023-03-14
问题内容

我已经使用GCM很长时间了。有一天,它突然破裂了。问题是我发送的第一个推送获得了成功状态,但该应用程序未收到任何推送。我发送的第二次推送失败,并显示NotRegistered错误。我重新安装该应用程序:成功(未收到通知),失败(未注册)->循环。我不知道发生了什么变化。Google支持非常无助,需要花费大量时间来回答简单的问题,无论是GCM问题,APNs问题还是客户问题。如果以前有人遇到过此类问题,请让我知道要查找的内容。看起来是这样的:

这是HTTP日志

我怀疑这是在更新到iOS 9之后发生的。但是我不确定。如果新iOS中有可能阻止GCM的东西,请有人指出。

那家伙也有类似的问题。问题出在某些清单文件上。我需要为iOS 9添加一些条目以允许GCM的Info.plist中吗?

更新:

每次应用启动时都会调用onTokenRefresh。不过,我又得到了相同的令牌。我怀疑GCM服务器上的令牌有问题。

GCM委派代码:

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]
}

更新

OK,所以我相信我搞砸了.plist位置(由于某种原因它不在根目录中)。我移到了根目录,现在在启动GCM时收到此警告/错误:

UPD。好的,它实际上只发生了一次并停止了。所以我不认为问题出在这里。

在将.plist移到根目录后,onTokenRefresh()调用停止了,但是我仍然没有注册。

错误


问题答案:

所以我解决了这个问题。看来我没有使用正确的iOS开发配置文件。我使用的是通用名称,而我的捆绑包名称需要使用特定的名称。发生这种情况的原因是因为我大约在一周前重新安装了操作系统,因此其他证书被清除了,并且直到我下载并将其手动添加到Xcode之前才起作用。我还需要从设备中删除团队供应配置文件。完全不是GCM或APNs故障。



 类似资料:
  • 我遇到了一个奇怪的问题,使用FCM向Android发送推送通知。 目标:-发送推送通知时出错 下面是一个场景,我确实有向Android发送推送通知的功能 所以问题是当我发送单个通知时,它可以正常工作,但当我发送多个通知时,我每次都出错 当我们调试代码时,我们的数据库中确实有设备令牌,没有停止发送推送通知的防火墙。 每次调用上述函数,我都会得到

  • 注册与访问 打开后台-会员-注册与访问 1.注册类型:普通注册/邮箱注册/手机注册 如开启邮箱和手机注册,请在通知系统功能中进行邮箱与短信通知配置,游客在注册时通过验证后方能注册成功 2.后台验证码是否开启:开启后显示 商城验证码是否开启:开启后显示 3.是否允许注册会员:设置为不允许则游客无法注册成为站点会员 4.错误多次后显示:配置该项后,开启验证码后验证码默认不显示,在登录错误次数达到设置值

  • 当我执行时,我的服务按预期列出,但当我从web或通过功能测试访问我的包时,我得到: 未捕获的PHP异常Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:“您请求了一个不存在的服务”xx。处理程序”在xx/app/bootstrap。php。缓存行2031{“异常”:“[对象](Symfony\Compo

  • 在64位计算机上运行Visual Studio 2012应用程序时,会显示以下错误消息: 由于以下错误,检索CLSID为{F2D4F4E5-EEA1-46FF-A83B-A270C92DAE4B}的组件的COM类工厂失败:80040154类未注册(HRESULT的异常:0x80040154(REGDB_E_CLASSNOTREG)) 我正在visualstudio中使用Inventor packa

  • 我使用的是Android GCM推送服务,它在一段时间内运行良好,但如果我让我的应用程序闲置几分钟,或者当我在代码修改后重新运行它时,我没有收到任何消息,GCM服务器给我这个错误:“NotRegistered”我做了一些重新搜索,我发现了这个问题,但我还不能在那里发表评论(低声誉:(而且帖子太旧了) 在浏览过程中,我发现Google服务器有时会自动刷新注册id,所以我需要知道的是GCM服务器何时对

  • 我尝试使用GCM发送APN。设备注册OK,GCM和IOS设备令牌被接收。当我尝试发送有效载荷没有"通知"节点: 一切正常。 但是我想处理应用程序在后台时的通知 根据文档,我将有效负载修改为: 第一次尝试: 但没有收到通知。 第二次尝试: 然后应用程序不会收到任何通知,即使我删除了通知节点。所以我必须移除它,重新安装,接收新的代币。 第二期: 我试图检查APN使用NWPusher,但得到错误:无效令