How to get unique id of apple watch programatically?

I am developing independent apple watch application.I need unique id of watch to register and call api.

And I know using xcode and attached device I get unique id but I need unique id programatically.

Accepted Reply

I don't think there is an equivalent to identifierForVendor in watchOS nor is there a keychain. Alternatively you could create your own UUID identifier and save it on the watch. You could also access the user's CloudKit database and use a CloudKit file (e.g. userRecord) associated with the user's Apple Id.

Replies

I don't think there is an equivalent to identifierForVendor in watchOS nor is there a keychain. Alternatively you could create your own UUID identifier and save it on the watch. You could also access the user's CloudKit database and use a CloudKit file (e.g. userRecord) associated with the user's Apple Id.

Yes I think about generate UUID my self and save it in watch but in one case I need solution.If user change the watch (or uninstall the app) then how to identified that user.

I use the keychain which, until Apple changes it again, survives deletion and reinstallation of the app. I don't believe there is such a thing in watchOS but you could rely on the keychain accessed by the app on the iPhone and watch connectivity. You could consider writing something to the user's userRecord on CloudKit. This will survive deletion and reinstallation of the app but it is associated with the user's Apple ID not the device.


Apple is fighting against your desire to tag the device with a user identity because they want a user to be able to sell the device and wipe it clean prior to sale.

Thank you for answer.


For now I go through timestamp and make it my unique id (Yes getting problem when deletion and reinstallation of the app because keychain also delete value during uninstall).

You can generate a random ID and store it in the KeyChain using https://github.com/st3fan/PersistentIdentifier/

Now there is an equivalent for identifierForVendor in watchOS.

if let uuid = WKInterfaceDevice.current().identifierForVendor?.uuidString {
	print("UUID is",uuid)
}

This can be used to generate a unique ID.