2015-10-15 142 views
1

我重新編譯我的iOS9 iPhone應用程序和我越來越想爲GCM註冊時出現錯誤,如下注冊:GCM失敗與1003錯誤

登記GCM失敗,出現錯誤:操作不能完成。 (com.google.iid error 1003.)

我已經找了一段時間了,在Google上找不到任何東西。 任何人都可以幫助我嗎?

在此先感謝

從下面appdelegate.swift代碼:

var connectedToGCM = false 
var subscribedToTopic = false 
var gcmSenderID: String? 
var registrationToken: String? 
var registrationOptions = [String: AnyObject]() 

let registrationKey = "onRegistrationCompleted" 
let messageKey = "onMessageReceived" 
let subscriptionTopic = "/topics/global" 

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

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

GCMService.sharedInstance().startWithConfig(GCMConfig.defaultConfig()) 

    return true 
} 

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) 
{ 
    //Process the deviceToken and send it to your server 

    let tokenChars = UnsafePointer<CChar>(deviceToken.bytes) 
    var tokenString = "" 

    for var i = 0; i < deviceToken.length; i++ 
    { 
     tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]]) 
    } 

    GGLInstanceID.sharedInstance().startWithConfig(GGLInstanceIDConfig.defaultConfig()) 
    registrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken, 
     kGGLInstanceIDAPNSServerTypeSandboxOption:true] 
    GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID, scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler) 
} 

func registrationHandler(registrationToken: String!, error: NSError!) 
{ 
    if (registrationToken != nil) 
    { 
     self.registrationToken = registrationToken 
     print("Registration Token: \(registrationToken)") 
     APIManager.sharedInstance.setDeviceToken(registrationToken) 
     self.subscribeToTopic() 
     let userInfo = ["registrationToken": registrationToken] 
     NSNotificationCenter.defaultCenter().postNotificationName(
      self.registrationKey, object: nil, userInfo: userInfo) 
    } 
    else 
    { 
     print("Registration to GCM failed with error: \(error.localizedDescription)") 
     let userInfo = ["error": error.localizedDescription] 
     NSNotificationCenter.defaultCenter().postNotificationName(
      self.registrationKey, object: nil, userInfo: userInfo) 
    } 
} 
+0

我們能看到一些代碼嗎?可能有助於診斷問題。 –

+0

我已添加代碼 – Luben

回答

0

這是在我身邊一個愚蠢的錯誤。 'GoogleService-Info.plist'被錯誤地命名並放置在錯誤的地方,它不在我的構建階段 - >複製束資源。

+0

我已將它放入項目的根文件夾並添加到我的目標。它被命名爲GoogleService-Info.plist。不過,我仍然收到同樣的錯誤;任何想法? – danielemm

2
1003 error talks "Token request has invalid authorizedEntity." 

就我而言gcmSenderID爲零。

也許你沒有使用GoogleService-Info.plistgcmSenderID。若要從GoogleService-Info.plist導入設置插入此代碼

var configureError:NSError? 
     GGLContext.sharedInstance().configureWithError(&configureError) 
     assert(configureError == nil, "Error configuring Google services: \(configureError)") 
     gcmSenderID = GGLContext.sharedInstance().configuration.gcmSenderID 

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

谷歌錯誤1003

我在根文件夾中GoogleService-info.plist中。 在我的情況下gcmSenderID甚至不是null,但我仍然收到此錯誤。

但我錯過了在didFinishLaunchingOptions下的AppDelegate.m文件中的這段代碼。

NSError* configureError; [[GGLContext sharedInstance] configureWithError:&configureError]; NSAssert(!configureError, @"Error configuring Google services: %@", configureError); _gcmSenderID = [[[GGLContext sharedInstance] configuration] gcmSenderID];