ios - How to trigger communication with backend from Apple Watch? -
i want click on push notification on apple watch trigger communication backend , show results in table on apple watch.
i know how show result in table on apple watch. know openparentapplication:reply:
method.
but if want trigger backend communication in application:handlewatchkitextensionrequest:reply:
error reply()
never called. seems ios kill method if takes time.
if test application:handlewatchkitextensionrequest:reply:
hard coded dictionary 1 entry, works fine.
that recommended way this?
in opinion should in notificationcontroller.swift in didreceiveremotenotification
method , app group how can trigger backend communication on iphone?
update:
part of code in appdelefate.swift:
func application(application: uiapplication!, handlewatchkitextensionrequest userinfo: [nsobject : anyobject]!, reply: (([nsobject : anyobject]!) -> void)!) { var workaround: uibackgroundtaskidentifier? workaround = uiapplication.sharedapplication().beginbackgroundtaskwithexpirationhandler({ uiapplication.sharedapplication().endbackgroundtask(workaround!) }) dispatch_after(dispatch_time(dispatch_time_now, int64(2 * nsec_per_sec)), dispatch_get_main_queue(), { uiapplication.sharedapplication().endbackgroundtask(workaround!) }) var realbackgroundtaks: uibackgroundtaskidentifier? realbackgroundtaks = uiapplication.sharedapplication().beginbackgroundtaskwithexpirationhandler({ reply(nil) uiapplication.sharedapplication().endbackgroundtask(realbackgroundtaks!) }) let testdict = ["hello" : "world"] reply(testdict) uiapplication.sharedapplication().endbackgroundtask(realbackgroundtaks!) }
this code works fine. if change testdict backend communication code method killed.
you'll need start background task on iphone ensure app isn't killed in background before api request can complete. i've shared resources in similar answer here: https://stackoverflow.com/a/29848521/3704092
Comments
Post a Comment