sms - iphone app exit with "No SIM card installed" -


i use mfmessagecomposeviewcontroller sending in app sms. in iphone 4.0, if there no sim card, app exits. gives pop message "no sim card installed". delegate callback messagecomposeresultsent. application exits. there way prevent exiting? or how check if there sim card in phone?

code snippets below:

    /* open system sms service, copying sms text in system clipboard. */ - (void) sendsmsasurlrequest {     nsstring *phonenumber = friend.phonemobile;     uipasteboard *pasteboard = [uipasteboard generalpasteboard];     nsstring *textutitype = (nsstring *)kuttypeutf8plaintext; // add mobilecoreservices.framework type.     [pasteboard setvalue:[self buildsmstext] forpasteboardtype:textutitype];     nsstring *urlstring = [nsstring stringwithformat:@"sms:%@", phonenumber];     nsurl *url = [[nsurl alloc] initwithstring: urlstring];     [[uiapplication sharedapplication] openurl: url];     [url release]; }  -(void) sendinappsms {     mfmessagecomposeviewcontroller *controller = [[[mfmessagecomposeviewcontroller alloc] init] autorelease];     controller.delegate = self;     if([mfmessagecomposeviewcontroller cansendtext])     {         nsstring *smstext = [self buildsmstext];         controller.body = smstext;         controller.recipients = [nsarray arraywithobjects:friend.phonemobile, nil];         controller.messagecomposedelegate = self;                 [self presentmodalviewcontroller:controller animated:yes];     } }  - (void)messagecomposeviewcontroller:(mfmessagecomposeviewcontroller *)controller didfinishwithresult:(messagecomposeresult)result {     switch (result) {         case messagecomposeresultcancelled:             nslog(@"cancelled");             break;         case messagecomposeresultfailed:{             nsstring *alertstring = nslocalizedstring(@"unknown error. failed send message", @"");             uialertview *alert = [[uialertview alloc] initwithtitle:nil message:alertstring delegate:self cancelbuttontitle:@"ok" otherbuttontitles: nil];             [alert show];             [alert release];             break;         }         case messagecomposeresultsent:             nslog(@"sms sent");             break;         default:             break;     }         [self dismissmodalviewcontrolleranimated:yes]; } 

to detect sim card installed or not use following code :

@import coretelephony;   cttelephonynetworkinfo *networkinfo = [cttelephonynetworkinfo new]; ctcarrier *carrier = [networkinfo subscribercellularprovider]; if (!carrier.isocountrycode) {     uialertview *alert = [[uialertview alloc]initwithtitle:@"no sim card installed" message:nil delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil, nil];     [alert show]; } else{ //paste code here } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -