代码之家  ›  专栏  ›  技术社区  ›  karim

iPhone应用退出“未安装SIM卡”

  •  1
  • karim  · 技术社区  · 14 年前

    我使用mfmessagecomposeviewcontroller发送应用程序内的短消息。在iPhone4.0中,如果没有SIM卡,应用程序将退出。它只会弹出一条信息:“未安装SIM卡”。 委托回调消息composeresultssent。但应用程序退出。有没有办法阻止它退出?或者如何检查手机中是否有SIM卡?

    下面的代码段:

        /* Open the system sms service, copying the sms text in system clipboard. */
    - (void) sendSMSAsURLRequest {
        NSString *phoneNumber = friend.phoneMobile;
        UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
        NSString *textUTIType = (NSString *)kUTTypeUTF8PlainText; // add MobileCoreServices.framework for this 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 to 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];
    }
    
    2 回复  |  直到 9 年前
        1
  •  1
  •   Alok    9 年前

    @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 Your code here
    }
    
        2
  •  0
  •   karim    14 年前

    - (void)applicationWillResignActive:(UIApplication *)aNotification {
        if (shouldExitApp) {
            exit(0);
        }
    }
    

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
    {
        ((LuupAppDelegate *)[[UIApplication sharedApplication] delegate]).shouldExitApp = NO;
    

    - (void) viewDidAppear:(BOOL)animated {
        ((LuupAppDelegate *)[[UIApplication sharedApplication] delegate]).shouldExitApp = YES;
        [super viewDidAppear:animated];
    
    }