Search code examples
swiftwatchkit

How can I programmatically compose a message on Watch?


How can I open the Messages app to the compose screen, with the message body preloaded with specific text?


Solution

  • Thanks to @Jatin for finding the openSystemURL(url: NSURL) function.

    Here's the code:

    let messageBody = "Hello World!"
    let urlSafeBody = messageBody.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
    WKExtension.sharedExtension().openSystemURL(NSURL(string: "sms:&body=\(urlSafeBody)")!)