ios - parse push notification acting peculiarly -


after nighter enough caffeine kill small rhino, got parse push notifications working realize not act expected.

the notifications sent, , received in didreceiveremotenotification not acting coded. out of 5 test notifications sent, 2 worked perfectly. rest of time notification still appeared in notification center not interact didreceiveremotenotification.

since did work few times, i'm not sure code post since i'm assuming code in appdelegate fine. , certificates/ plist/ provisional profile must set correctly since notification alert comes through time.

so guess i'm wondering if there possible problems cause notifications work differently.

         if application.applicationstate != uiapplicationstate.background {         // track app open here if launch push, unless         // "content_available" used trigger background push (introduced in ios 7).         // in case, skip tracking here avoid double counting app-open.          let prebackgroundpush = !application.respondstoselector("backgroundrefreshstatus")         let oldpushhandleronly = !self.respondstoselector("application:didreceiveremotenotification:fetchcompletionhandler:")         var pushpayload = false         if let options = launchoptions {             pushpayload = options[uiapplicationlaunchoptionsremotenotificationkey] != nil          }         if (prebackgroundpush || oldpushhandleronly || pushpayload) {             pfanalytics.trackappopenedwithlaunchoptions(launchoptions)         }     } 

the problem begins here:

let oldpushhandleronly = !self.respondstoselector("application:didreceiveremotenotification:fetchcompletionhandler:") 

push notifications handled 2 different methods, depending on if app in background or foreground. means need have code in 2 different methods. trying detect if 1 method available isn't going help.

instead, need push push handler code in 2 places. ray wenderlich points out in excellent introduction push:

application:didfinishlaunchingwithoptions: if app wasn’t running when notification came in, launched , notification passed part of launchoptions dictionary.

application:didreceiveremotenotification: method invoked if app active when notification comes in. on ios 4.0 or later, if app suspended in background woken , method called. can use uiapplication’s applicationstate property find out whether app suspended or not.

make sure handling pushes in both places.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -