ios - Data is not being transferred from iphone to iWatch (AppleWatch) on real devices -


i have ios app , programmed extension on applewatch. i'm sending data (nsdictionary) applewatch extension using transferuserinfo method. works in simulator when i'm trying run application on real devices, seems iwatch not receiving though iphone sending data (i found cause debugged sender side).

i have configured wcsession on both sides. have conformed wcsessiondelegate in class i'm supposed receive data. i'm using session:didreceiveuserinfo: method receive data in extensiondelegate still said works fine in simulator nothing being transferred on real devices.

does has clue problem is?

here's code: in sender side:

inside class mensaviewcontroller.m

- (void)viewdidload    if ([wcsession issupported]) {         session = [wcsession defaultsession];         session.delegate = self;         [session activatesession];    }    nslog(@"a dish being sent");   [session transferuserinfo:dishdictionary]; } 

dishdictionary declared inside viewdidload method , contains data.

on receiver side (watch extension) configure wcsession , receive data in extensiondelegate.m this:

- (void)applicationdidbecomeactive {     if ([wcsession issupported]) {         session = [wcsession defaultsession];         session.delegate = self;         [session activatesession];         nslog(@"session activated in iwatch");     } } 

and have method receive data:

- (void)session:session didreceiveuserinfo:(nsdictionary<nsstring *,id> *)userinfo{      nslog(@"received data iphone");      nsarray<nsstring*> *dictionarykeys = userinfo.allkeys;     for(int = 0; < dictionarykeys.count; i++){         boolean equalsmensastring = [dictionarykeys[i] isequaltostring:@"beilagen"];         if(equalsmensastring)             [self handletransferreddish:userinfo];          boolean equalsnewsstring = [dictionarykeys[i] isequaltostring:@"article"];         if(equalsnewsstring)             [self handletransferrednews:userinfo];          boolean equalseventstring = [dictionarykeys[i] isequaltostring:@"description"];         if(equalseventstring)             [self handletransferredevents:userinfo];      } } 

if take @ sources function description, can see description of method using transferring data:

public func transferuserinfo(userinfo: [string : anyobject]) -> wcsessionuserinfotransfer 

the system enqueue user info dictionary , transfer counterpart app @ opportune time. transfer of user info continue after sending app has exited. counterpart app receive delegate callback on next launch if file has arrived. userinfo dictionary can accept property list types.

so..there's no guarantee system send userinfo while using app.

use following method instead:

public func sendmessage(message: [string : anyobject], replyhandler: (([string : anyobject]) -> void)?, errorhandler: ((nserror) -> void)?) 

clients can use method send messages counterpart app. clients wishing receive reply particular message should pass in replyhandler block. if message cannot sent or if reply not received, errorhandler block invoked error. if both replyhandler , errorhandler specified, 1 of them invoked. messages can sent while sending app running. if sending app exits before message dispatched send fail. if counterpart app not running counterpart app launched upon receiving message (ios counterpart app only). message dictionary can accept property list types.

and receiving:

func session(session: wcsession, didreceivemessage message: [string : anyobject], replyhandler: ([string : anyobject]) -> void) 

notice that: send can fail if counterpart app not open or session not paired , active. so, in case can not miss data should use updateapplicationcontext or transferuserinfo (i prefer updateapplicationcontext)

session.sendmessage(messagedata, replyhandler: { (replydata) -> void in             replyhandler?(replydata)             }, errorhandler: { (error) -> void in                 print("error: code:\(error.code) - \(error.localizeddescription)")                 errorhandler?(error)                  {                         try session.updateapplicationcontext(messagedata)                     } catch {                         print("there error trying update watchkit app on background")                     }         }) 

and make sure receive cases proper implementation of

func session(session: wcsession, didreceiveapplicationcontext applicationcontext: [string : anyobject])


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -