swift - How to receive a watchOS file transfer on iOS in the background -


i using transferfile , can send , receive files, in order complete transfer process, need open iphone app.

in observing other apps, appears able receive , act upon received data in background (and send push notification user, example).

i wondering how did this.

you should send message watch app phone using sendmessage function of watch connectivity requesting data. wake iphone app. in didreceivemessage method on phone should use filetransfer function send files watch.

to clarify when message sent using sendmessage wakes iphone application in background receive message can respond file transfer. hope helps

you need send message first before sending file transfer. implement on watch side

func sendactivationmessage() {     if session.activationstate == .activated && session.isreachable {         session.sendmessage(["watch message" : "activate"], replyhandler: {      (reply) in              if reply["phone message"] as! string == "activated" {                 //this should implement file transfer             }         }, errorhandler: { (error) in              print("***** error did occur: \(error) *****")         })     } else {         print("***** activation error *****")     } } 

then in didreceivemessage function on phone side implement this

func session(_ session: wcsession, didreceivemessage message: [string : any], replyhandler: @escaping ([string : any]) -> void) {      if let messagefromwatch = message["watch message"] {         let messagedata = messagefromwatch as! string          //message watch activate watch connectivity session         if messagedata == "activate" {             replyhandler(["phone message" : "activated"])         } } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -