如何打开消息应用到撰写屏幕,消息正文预加载了特定文本?
最佳答案
Benjy's answer is almost correct ,但有一个问题。
由于 urlSafeBody
未展开,字符串插值产生
sms:&body=Optional("Hello%20World!")
这导致 NSURL
初始化返回 nil,因为 URL 字符串格式错误。
这是一个有条件地解包可选值的工作示例。这消除了与 nil 可选值被强制展开相关的任何崩溃的可能性。
let messageBody = "Hello World!"
let urlSafeBody = messageBody.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet())
if let urlSafeBody = urlSafeBody, url = NSURL(string: "sms:&body=\(urlSafeBody)") {
WKExtension.sharedExtension().openSystemURL(url)
}
关于swift - 如何以编程方式在 Watch 上撰写消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34361531/