hannes hannes - 1 year ago 171
iOS Question

Is it possible to send complex Arrays from iPhone to AppleWatch with watch connectivity?

I have a problem passing data from iOS to WatchOS 2.0

I want to send an

to WatchOS but my
has no type like
but an
that I generated.

// here I fetch my Lists with Users
var friendList: [UserProfile] = Utils().loadUsers("friendList")
var blackList: [UserProfile] = Utils().loadUsers("blackList")
var users: [UserProfile] = Utils().loadUsers("UsersList")

// here I put the Lists in the Dictionary in order to send this Dictionary to Watch
let dictionary: [String: AnyObject]=[
"UsersList" : self.users,
"BlackList" : self.blackList,
"FriendList" : self.friendList

WCSession.defaultSession().sendMessage(dictionary, replyHandler: { (data) -> Void in
// handle the response from the device

}) { (error) -> Void in
print("error: \(error.localizedDescription)")

In my WatchApp Class I try to get the Data but there is following error:

error: Payload contains unsupported type.

This is how I want to get the Data. If I send
this works, but not for
like mine:

let userList: [UserProfile] = applicationContext["UsersList"] as! [UserProfile]
let blackList: [UserProfile] = applicationContext["BlackList"] as! [UserProfile]
let friendList: [UserProfile] = applicationContext["FriendList"] as! [UserProfile]

Hope anyone can help me with this Problem.

Answer Source

UserProfile objects friendList, blackList, users are not serialised yet, and cannot be directly send to Apple Watch.

You can convert them to dictionaries before sending them to the Apple Watch.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download