If you are sending data from the iPhone to the Apple Watch, you might use sendMessage
.
func sendMessage(_ message: [String : Any], replyHandler: (([String : Any]) -> Void)?, errorHandler: ((Error) -> Void)? = nil)
If you do this and get the error WCErrorCodePayloadUnsupportedTypes this is because you put an unsupported type in the message dictionary.
The first parameter (message
) is a dictionary of String
to Any
, but the value cannot really be any type. If you read the documentation, it says that message
is
A dictionary of property list values that you want to send. You define the contents of the dictionary that your counterpart supports. This parameter must not be
nil
.
“property list values” means values that can be stored in a Plist. This means you can use simple types like Int
, Bool
, and String
and you can also use arrays and dictionaries as long as they are of those simple types (e.g. an Array of Ints)
I ran into this issue because I tried to use a custom struct in the message dictionary, which is not supported.
Note: I made this post because google is sending people to Programming Tutorials Need to Pick a Type of Learner because it mentions WCErrorCodePayloadUnsupportedTypes incidentally, but isn’t really about that.