ios - Why is didReceiveRemoteNotification not called but didReceiveRemoteNotification:fetchCompletionHandler called when my app is in the foreground? -


if override

override func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject], fetchcompletionhandler completionhandler: (uibackgroundfetchresult) -> void) {     println("hey) } 

i have method called app in foreground when send push notification.

if override

override func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject]) {     println("hey") } 

i don't call method when sending notification app in foreground. why first 1 work, second 1 doesn't when app in foreground?

note implementing 1 of these @ time. not both @ same time.

you should use callback version unless need support ios<7 (when introduced). using swift expect not case.

the older method goes ios3 , deprecated in name:

implement application:didreceiveremotenotification:fetchcompletionhandler: method instead of 1 whenever possible. if delegate implements both methods, app object calls application:didreceiveremotenotification:fetchcompletionhandler: method.

the older version give different results depending on whether app live (foreground or background) or launches cold start. in latter case, not called, , need intercept launchoptions dict on didfinishlaunchingwithoptions @ infodict:

if app not running when remote notification arrives, method launches app , provides appropriate information in launch options dictionary. app not call method handle remote notification.

use callback version. works cases. you don't have use completion handler/block, in case effect same (well, more consistent newer method).

update

sorry, apple says do have call completion block "as possible" - have 30 seconds before os gives on you. might source of warning.

as finish processing notification, must call block in handler parameter or app terminated. app has 30 seconds of wall-clock time process notification , call specified completion handler block. in practice, should call handler block done processing notification.

so call completion block:

        completionhandler(uibackgroundfetchresult.nodata) 

i have been using method without calling completion block , haven't experienced problems, add 1 safe. apple suggests if don't, app won't foregrounded have not seen in practice.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -