Passing Data From A Class To WatchOS 2 (Connectivity)

ZbadhabitZ

I'm hoping someone here may have some thoughts on Watch OS 2 connectivity that can point me in the right direction. Succinctly, I am trying to pass a set of data (from a custom class called FileData) to my WatchKit extension. When I run the WatchKit app, I can see that the WCSession is being activated, but the dataset never seems to get passed to the Watch (though if I change the data to a String and pass something simple like "hello", it does work properly);

TableViewController.swift (iOS side)

...
func sendToWatch(files: [FileData]) {
    let session = WCSession.defaultSession()
    let applicationData = ["myFiles":[FileData](files)]
    session.sendMessage(applicationData, replyHandler: { reply in
        print("Got reply: \(reply)")
    }, errorHandler: { error in
        print("error: \(error)")
    })
}
...

InterfaceController.swift (WatchKit extension)

...
func session(session: WCSession, didReceiveMessage message: [String : AnyObject]) {
    let files = message["myFiles"] as! [FileData]
    print("Got a message")
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            print(files)
        })

    reloadTable()
}
...

Am I wrong in assuming that I can pass a custom class via Watch Connectivity? Or have I done something wrong here?

Thank you!

ccjensen

Yes, that is an incorrect assumption. The WCSession sendMessage documentation states that the dictionary may only contain property list types which are basic types such as strings, integers, floats, data, etc. So to send your content, either convert the object to a dictionary of key-value pairs or use the less recommended approach of using NSKeyedArchiver to convert your object directly to data.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Struts 2 passing data from JSP to action class

From Dev

Passing data from the class to the MainActivity

From Dev

WatchOS2 Watch Connectivity still require app groups in capabilities?

From Dev

watchOS2 and iOS8 connectivity - Swift

From Dev

WatchOS2 connectivity framework doesn't work

From Dev

Swift Passing data from appDelegate to another class

From Dev

passing data from BroadcastReceiver to class that extends runnable

From Dev

Xamarin Android passing data from class to activity

From Dev

WatchOS fetching data from iPhone

From Dev

Sending core data to watchOS 2

From Dev

Sending core data to watchOS 2

From Dev

Struts2 - passing data from jsp form fields with same name to action class

From Dev

passing data from UITabBarView Class to sub class of UIViewController using swift

From Dev

Passing data from a class that 'extends activity' to a class that 'extends fragment'

From Dev

Angular 2 - passing data from service to component

From Dev

Passing through data from 2 mongodb objects

From Dev

Migrate my app from WatchOS1 to WatchOS2

From Dev

Class Structure and Passing Data

From Dev

WatchOS 2 best practice for storing/retrieving data

From Dev

Passing data for list view from Asynctask to a custom list adapter class

From Dev

passing data from controller to model class mvc-5

From Dev

How to load image from URL on watchos 2?

From Dev

passing a variable from class to class

From Dev

passing variable from action class(struts2) to JSP

From Dev

passing variable from action class(struts2) to JSP

From Dev

Passing data from IntentService

From Dev

Passing data from IntentService

From Dev

Passing data from column

From Dev

Passing data from UITableViewCell

Related Related

HotTag

Archive