手机偶尔会收到iMessage的推送广告,所以就调查了iMessage群发推广的技术实现以及可行度(当然,后来调查了一下,这个行为会引起用户的反感,所以也就不了了之了)
其中,iMessage群发的介绍,在这里就不赘述了,这里贴出两篇觉得干货的博客
https://daily.zhihu.com/story/732826
总体来讲,现在实现主要是分两种方案:
- 使用AppleScript来操作iMessage客户端,实现群发,不过有个很严重的限制,就是必须iMessage客户端验证过的才能发送成功(这个说法有点绕,我验证的就是必须iMessage中得有与这个人的对话)
https://blog.csdn.net/templar1000/article/details/12995213 - 使用虚拟机/(没找到这种形式是怎么解决:必须iMessage中有与对方的对话,才能操作)
https://www.jianshu.com/p/d7116ad61ee5
主要说一下第一种
主要是同时也学习一下AppleScript脚本语言
网上的经常会报一些错误,经过几个版本的结合,现在整理了两个可用版本,一个是单发,一个是群发
单发
tell application "Messages"
set myid to 1st service whose service type = iMessage
set theBuddy to buddy "+86xxx" of myid
repeat with i from 1 to 1
send "hello, 测试一下AppleScript哈" to theBuddy
end repeat
end tell
群发
代码中,可用通过读取本地的cav文件来读取联系人,也可直接定义一个数组来测试
tell application "Messages"
#set csvData to read "/Users/xxxx/Desktop/test.csv"
#set csvEntries to paragraphs of csvData
#repeat with i from 1 to count csvEntries
set csvEntries to {"+86xx", "+86xx", "+86xx"}
repeat with phone in csvEntries
#set phone to (csvEntries's item i)'s text
set myid to (1st service whose service type = iMessage)
set theBuddy to buddy phone of myid
send "今天北京晴,气温13到27度;周二晴,气温11到26度,北风3-4级;周三晴,气温11到24度,微风<3" to theBuddy
#-延时一秒,不然取不到已发达的内容
# 及时删除多余的消息
delay 1
set FailNum to (get count chat)
if FailNum > 100 then
repeat with j from 1 to FailNum
set phone to (get name of chat (FailNum - j))
set DelMsg to "iMessage;-;" & phone
if exists (text chat id DelMsg) then
delete text chat id DelMsg
end if
end repeat
end if
end repeat
end tell
下面附带两篇AppleScript的学习使用
语法学习:https://segmentfault.com/a/1190000011273388#articleHeader9
使用:http://www.cocoachina.com/ios/20180402/22870.html -- MrPark