2013-03-19 9 views
7

Sto lavorando su alcune app iOS, tutte con lo stesso editore, che hanno tutte le notifiche push abilitate. Quando chiamo registerForRemoteNotificationTypes, ottengo il prompt dell'utente per consentire o disabilitare le notifiche push, ma io application:didRegisterForRemoteNotificationsWithDeviceToken: viene chiamato con i dati token prima dello l'utente sceglie un'opzione. E viene chiamato di nuovo quando premono OK. È normale?APNS didRegisterForRemoteNotifiche chiamate prima che l'utente permetta le notifiche su iOS

Nota: più app sembrano ottenere lo stesso token quando sono in esecuzione sullo stesso dispositivo.

+0

Non sono sicuro della tua domanda principale, ma per quanto riguarda la nota - è normale. Tutte le applicazioni sullo stesso dispositivo ricevono lo stesso token dispositivo. – Eran

+0

Potrebbe essere stata già consentita l'app in precedenza per la ricezione di notifiche push. Cerca la tua app in impostazioni-> notifiche per verificare se è già lì. – msk

+0

@MSK - Ma se l'ho già permesso, allora non dovrebbe presentare il prompt di sistema che chiede all'utente se vuole consentire le notifiche push. Mi sbaglio? –

risposta

6

Questo è da documenti Apple.

When you send this message, the device initiates the registration process with Apple Push Service. If it succeeds, the application delegate receives a device token in the application:didRegisterForRemoteNotificationsWithDeviceToken: method; if registration doesn’t succeed, the delegate is informed via the application:didFailToRegisterForRemoteNotificationsWithError: method. If the application delegate receives a device token, it should connect with its provider and pass it the token.

E

The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.

Credo che ciò che si sta osservando è normale. Non si fa menzione che application:didRegisterForRemoteNotificationsWithDeviceToken verrà chiamato solo se l'utente concede il permesso. Penso che puoi ottimizzarlo memorizzando nella cache il token del dispositivo in NSUserDefaults e in questo metodo controlla se il nuovo token non è uguale al token memorizzato nella cache.

+0

Mi sembra illogico ricevere un token se le notifiche push vengono disabilitate a livello di sistema. Ma in effetti, se vado in Impostazioni e disabilito tutte le risorse push per questa app, viene comunque richiamato con un token. Penso tu abbia ragione. –

+0

cosa sono le notifiche push di abilitazione utente quando la tua app è in background. Quando lo lanci non hai token nel tuo server e iOS non chiamerà didFinishLaunchingWithOptions quando lo avvii dallo sfondo. – msk

2

È una vecchia domanda, ma ho appena riscontrato questo problema e sembra essere correlato alla modalità di background di notifica remota. application:didRegisterForRemoteNotificationsWithDeviceToken viene chiamato sul mio iPhone prima di accettare l'autorizzazione di notifica push solo quando questa modalità in background è attivata.

Problemi correlati