ios - Push notifications that trigger a background refresh before showing the push notification VS silent push -


i want implement background refresh functionality in app when push received. before push notification displayed user want download new messages backend (parse.com) , save them array. following guide here: http://developer.xamarin.com/guides/ios/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/

i'm not sure how accurate guide is. states: ios 7 (and greater) extends ordinary push notifications giving applications chance update content in background before notifying user, user can open application , presented new content immediately.

so tried implementing background push this:

- (void)application:(uiapplication *)application didreceiveremotenotification:(nsdictionary *)userinfo fetchcompletionhandler:(void (^)(uibackgroundfetchresult result))handler {       if([[userinfo objectforkey:@"aps"] objectforkey:@"content-available"]){          nslog(@"doing background refresh");         uinavigationcontroller *navigationcontroller=(uinavigationcontroller *)[[[uiapplication sharedapplication] keywindow] rootviewcontroller];          myviewcontroller *myviewcontroller = (myviewcontroller *)[[navigationcontroller viewcontrollers] objectatindex:1];          [myviewcontroller.currentuser refreshmessagesarraywithcompletionhandler:^(bool successful, bool newmiaos) {              nslog(@"messages refreshed array has %lu messages",(unsigned long)[myviewcontroller.currentuser.messages count]);             handler(uibackgroundfetchresultnewdata);         }];     } } 

the background refresh called , push displayed, push notification not wait background task finish. displayed received. correct functionality? tutorial above suggests notification won't displayed until background task completed.

i went trying silent notification, triggers app download messages in background when push received no notification displayed. firing local notification instead after download completes. correct way of doing it? traditional apps such whatsapp trigger background refresh using silent notification , fire local one? seems bit hacky. surely idea of background push data ready before showing notification doesn't quite work that..

the other thing noticed silent notifications rate limited have lower priority typical push notification surely hinders efficiency of app also...

any pointers on appreciated. trying head around if i'm approaching right way or not. seems hacky...

i've been struggling same task in messaging app. wanted users see message right before user taps notification. faced with:

  • the payload size limitation. ios 7 can have 256 bytes payload
  • single silent notifications not start app, if not running
  • content-available notifications without alert body may not delivered device
  • background fetch not controlled app, may never receive desired signal, cannot rely on feature. may helpful additional way achieve want
  • ios 8 has lot of space payload - 2kb
  • if send alert body and content-available - delivered in cases , app able process it

so came acceptable solution: decided make feature in ios8+ only. send visible push notifications content-available key allows process notification payload if process running/frozen , both able present notification if app not running. if app receives push notification, takes alert text body , writes local database, user able read in conversation. according our stats, average size of message not more 200 symbols, of time no requests required. if message longer 200 symbols, extend payload body parameter used request text body in push notification processing. user see cropped version of text, after request done, rewrite message in local database received value.

so, technique allows show received message user in of cases + if app not running, make request our server fetch missing messages right after application start. fastest , acceptable case on ios. hope experience implement want.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -