how can i detect that received sms is read or not by user, i am using CTMessageCenter header also pleas help me..开发者_C百科
and also tell me how can i put my application in background continuously....
i think there is no method from which we can found that message is read or not in non jailbreak ...
Ya you can read your incoming message and send also.In your main.m write this code and use three files:CoreTelephony.h,CTMessage.h,CTMessageCenter.h One problem with this using this way you can't submit your app on app store.
static void callback(CFNotificationCenterRef center, void *observer, NSString* name, const void *object, NSDictionary* info) {
fprintf(stderr, "Notification intercepted: %s\n", [name UTF8String]);
if([name isEqualToString:@"kCTMessageReceivedNotification"] && info)
{
NSNumber* messageType = [info valueForKey:@"kCTMessageTypeKey"];
if([messageType isEqualToNumber:[NSNumber numberWithInt:1]])
{
NSNumber* messageID = [info valueForKey:@"kCTMessageIdKey"];
CTMessageCenter* mc = [CTMessageCenter sharedMessageCenter];
CTMessage* msg = [mc incomingMessageWithId:[messageID intValue]];
NSObject<CTMessageAddress>* phonenumber = [msg sender];
NSString *senderNumber = (NSString*)[phonenumber canonicalFormat];
NSString *sender = (NSString*)[phonenumber encodedString];
CTMessagePart* msgPart = [[msg items] objectAtIndex:0]; //for single-part msgs
NSData *smsData = [msgPart data];
NSString *smsText = [[NSString alloc] initWithData:smsData encoding:NSUTF8StringEncoding];
fprintf(stderr, "SMS Message from %s / %s: \"%s\"\n",[senderNumber UTF8String],[sender UTF8String],[smsText UTF8String]);
}
}
return;
}
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(ct, NULL, callback, NULL, NULL, CFNotificationSuspensionBehaviorHold);
// Start the run loop. Now we'll receive notifications.
[[NSRunLoop currentRunLoop] run];
NSLog(@"you are in main thread");
[pool drain];
printf("Unexpectedly back from CFRunLoopRun()!\n");
[pool release];
}
精彩评论