我搜索的SO问这个问题之前,有没有满足我的需要的答案。
所以这是我的要求,
我有这样的一段代码,用于检测传入的短信,但它并没有说如何转储这些消息。 我已经成功地阻止了来电,但对于消息我不知道如何做到这一点。 这里的任何帮助将是非常赞赏。
我在使用任何私有的API确定。
if ([notifyname isEqualToString:@"kCTSMSMessageReceivedNotification"])
{
if ([[(NSDictionary *)userInfo allKeys]
containsObject:@"kCTSMSMessage"]) // SMS Message
{
CTSMSMessage *message = (CTSMSMessage *)
[(NSDictionary *)userInfo objectForKey:@"kCTSMSMessage"];
NSString *address = CTSMSMessageCopyAddress(NULL, message);
NSString *text = CTSMSMessageCopyText(NULL, message);
//NSArray *lines = [text componentsSeparatedByString:@"\n"];
printf(" %s %s\n", [address UTF8String],[text UTF8String]);
//printf(" %s\n", [text cString]);
fflush(stdout);
}
}
else if ([notifyname isEqualToString:@"kCTMessageReceivedNotification"])//received SMS
{
/*
kCTMessageIdKey = "-2147483636″;
kCTMessageTypeKey = 1;
*/
NSDictionary *info = (NSDictionary *)userInfo;
CFNumberRef msgID = (CFNumberRef)[info objectForKey:@"kCTMessageIdKey"];
int result;
CFNumberGetValue((CFNumberRef)msgID, kCFNumberSInt32Type, &result);
/*
Class CTMessageCenter = NSClassFromString(@"CTMessageCenter");
id mc = [CTMessageCenter sharedMessageCenter];
id incMsg = [mc incomingMessageWithId: result];
int msgType = (int)[incMsg messageType];
if (msgType == 1) //experimentally detected number
{
id phonenumber = [incMsg sender];
NSString *senderNumber = (NSString *)[phonenumber canonicalFormat];
id incMsgPart = [[incMsg items] objectAtIndex:0];
NSData *smsData = [incMsgPart data];
NSString *smsText = [[NSString alloc] initWithData:smsData encoding:NSUTF8StringEncoding];
}
*/
}
由于纳文