With ios4.x I can use code below to get the message when get the “kCTMessageReceivedNotification” notification
CTTelephonyCenterAddObserver( ct, NULL, callback,NULL,NULL, CFNotificationSuspensionBehaviorHold);
if ([notifyname isEqualToString:@"kCTMessageReceivedNotification"])//receive message
{
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];}
But with ios5 I can’t do it as incMsg is nil,so what can i do to get the message?
Thanks
Here’s what I found …
Just looking at the dumped private APIs, it looks like ChatKit.framework could help. Take a look at
CKSMSService.h
or CKMadridService.h for iMessage messages.
I did quickly attempt to swizzle my own method in, for a couple methods in
CKSMSService:but on iOS 5.0.1 I didn’t see either of those get called (maybe my error?). So, I tried to just get the message directly from the sqlite SMS database. Note … I didn’t build the full app, to register for notifications. I’m assuming your code to get the
kCTMessageReceivedNotificationis ok … it just doesn’t give you the SMS content anymore. So, if you put the following code in your notification handler, you should be able to see the message text:Now, make sure this app is installed in /Applications/. If you just build this app, and install normally with Xcode, you’ll get a permission denied error opening the sqlite database, because of app sandboxing.
My code snippet just gets the most recent text content. Here’s an example of doing a little more with the database. Look at the
QuerySMSmethod.Also, here’s a link on the database format of sms.db. You can find what else you need in there. Or, just copy the sms.db to your computer, and browse it with something like the Firefox SQLiteManager plugin. Good luck!
Update: some information from a question I posted on multi-process SQLite thread safety on iOS