我想在macOS上使QR码可操作。我发现只使用imessage作为URI或sms作为URI就可以打开Messages app:
NSString *message = @"imessage://[email protected]";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:message]];
NSString *message = @"sms://[email protected]";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:message]];
但是我无法添加任何参数,因此我可以预先填充文本正文。如何预先填充身体?
sms URI仅在10.14 Mojave之后。
PS:使用逗号为iMessage URI分隔电子邮件将进行群聊。
处理URL(_handleGURL ..)的Messages.app方法获取此NSAppleEventDescriptor:
(lldb) po $rdx
<NSAppleEventDescriptor: 'GURL'\'GURL'{ '----':"imessage://[email protected]", 'qtnp':'qtnd'($62706C6973743030D2010203045F10214C5351756172616E74696E654167656E7442756E646C654964656E7469666965725F10154C5351756172616E74696E654167656E744E616D655F1011636F6D2E6872756261736B6F2E7363616E50080D31495D000000000000010100000000000000050000000000000000000000000000005E$) }>
根据商业聊天框架的Starting a Chat from a URL:
您可以在网址中包含可选的查询字符串参数:“biz-intent-id”“biz-group-id”“body”
NSURL *URL = [NSURL URLWithString:@"sms:[email protected]&body=Order%20additional%20credit%20card"];
[[NSWorkspace sharedWorkspace] openURL:URL];
但是这对iMessage URI不起作用(内部实现为消息值设置nil)