6

Utilizzo GCM già da molto tempo. Un giorno improvvisamente si ruppe. Il problema è che il primo push che invio riceve lo stato di successo ma l'app non riceve alcun tipo di push. Il secondo push che invio riceve un errore con un errore NotRegistered. Installa di nuovo l'app: esito positivo (nessuna notifica ricevuta), errore (NotRegistered) -> Loop. Non so cosa è cambiato. Il supporto di Google non è di grande aiuto e richiede molto tempo per rispondere a una semplice domanda, indipendentemente dal fatto che si tratti di problema GCM, problema APN o problema del client. Se qualcuno ha già avuto questo problema, per favore fammi sapere cosa cercare. Che è come sembra:GCM IOS NotRegistered issue

Here is the HTTP log

Ho il sospetto che è successo dopo l'aggiornamento a iOS 9. Non sono sicuro però. Se ci sono cose nel nuovo iOS che potrebbero bloccare GCM, sarei grato se qualcuno lo facesse notare.

UPDATE:

GCM push fails with NotRegistered

quel ragazzo ha avuto un problema simile. Il problema era con alcuni file manifest. Potrebbero esserci alcune voci in Info.plist che devo aggiungere per iOS 9 per consentire GCM?

UPDATE:

onTokenRefresh viene chiamato ogni volta che i lanci di app. Ricevo lo stesso token, però. Quindi, sospetto, c'è un problema con un token su un server GCM.

GCM CODICE delegato 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, quindi credo che ho incasinato con la posizione .plist (non era nella radice per qualche motivo) . Mi sono trasferito alla radice e ora sto ricevendo questo avviso/errore all'avvio di GCM:

UPD. Ok, è successo solo una volta e si è fermato. Quindi non penso che il problema sia qui.

Dopo aver spostato .plist nella directory principale suTokenRefresh() le chiamate sono state interrotte, ma sto ancora ricevendo NotRegistered.

Error

+0

È possibile includere i callback implementati nel delegato dell'applicazione per GCM? –

+0

Questo di solito accade con un token APN non valido. Sei sicuro che il token APNS che stai utilizzando per registrarti con GCM sia valido per il server in particolare. Ad esempio, non stai utilizzando un token APNS Sandbox per inviare messaggi alla tua app firmata con certificato PROD. Assicurati inoltre di assegnare correttamente il valore a 'kGGLInstanceIDAPNSServerTypeSandboxOption' quando ti registri con GCM. – evanescent

+0

Sto usando l'opzione sandbox giusta.Come posso verificare se il token non è valido? –

risposta

5

Così ho risolto il problema. Sembrava che non stavo usando il profilo di provisioning di sviluppo iOS giusto. Stavo usando uno generico, mentre dovevo usare uno specifico per il mio nome del pacchetto. Il motivo è che ho reinstallato il mio sistema operativo una settimana fa circa, quindi l'altro certificato è stato cancellato e non ha funzionato fino a quando non ho scaricato e aggiunto manualmente a Xcode. Inoltre, dovevo eliminare anche il profilo di provisioning del team dal dispositivo. Assenza totale di errori GCM o APN.

+1

Mi è successo e il profilo di provisioning è quello che ha funzionato anche per me. Penso che iniziò a succedere dopo aver aggiornato iOS e xcode, ho dovuto scaricare di nuovo il mio profilo di provisioning. – CodeSmith

+1

Davvero utile! Grazie mille per aver chiesto e risposto a questa domanda! –