ios - Doing http request with silent notification -


i want use silent push notification in app. enabled background modes on app , phone.

when silent notification arrives didreceiveremotenotification delegate method calling. can't http request in method. using following code:

func application(application: uiapplication, didreceiveremotenotification userinfo: [nsobject : anyobject], fetchcompletionhandler completionhandler: (uibackgroundfetchresult) -> void) {     print("step 1")     let request = nsmutableurlrequest(url: nsurl(string: "url")!)     request.httpmethod = "post"     let poststring = "search=\(username)&me=\(anonid)"     request.httpbody = poststring.datausingencoding(nsutf8stringencoding)     let task = nsurlsession.sharedsession().datataskwithrequest(request) {         data, response, error in         print("step 2")         if error == nil {             let jsonresult: dictionary = (try! nsjsonserialization.jsonobjectwithdata(data!, options: nsjsonreadingoptions.mutablecontainers)) as! dictionary<string, anyobject>             let results = jsonresult["result"] as! [[string: anyobject]]             print(results)             item in results {              }             completionhandler(uibackgroundfetchresult.newdata)         }     } } 

when notification arrives, see step 1 text on console. can't see step 2 text.

how can fix problem?

you need set url session supports background downloading , use that. search on "background" in nsurlsession class reference info on how that.

i don't think have ask background time in order initiate background download. should have enough time that.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo