首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用程序短信中的iPhone iOS 5软件开发工具包错误

应用程序短信中的iPhone iOS 5软件开发工具包错误
EN

Stack Overflow用户
提问于 2012-04-13 12:34:00
回答 1查看 377关注 0票数 0

提前感谢我每次调用创建应用程序中的SMS时,我都会收到以下错误...

应用程序尝试在目标上推送nil视图控制器。

这是我在OS4SDK中工作的代码...

代码语言:javascript
复制
MFMailComposeViewController *MailController;
MFMessageComposeViewController *SMScontroller;
NSError *error;
NSString *EmailMessage;
NSString *SubjectMessage;

-(IBAction)sendInAppSMS
{

    if([MFMessageComposeViewController canSendText])
    {
        SMScontroller = [[MFMessageComposeViewController alloc] init];
        SMScontroller.messageComposeDelegate = self;

        NSString *MessageString = @"Hello";

        SMScontroller.body = MessageString;

        SMScontroller.navigationBar.tintColor = [UIColor blackColor];

        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

        [self presentModalViewController:SMScontroller animated:YES];

        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
    }
    else{
        // alertView to tell user to setup a mail account. 
        NSString *message = [[NSString alloc] initWithFormat:@"To use this feature, you need to have an iPhone with SMS abilities."];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"SMS Account Not Detected" message:message delegate:nil cancelButtonTitle:@"Understood" otherButtonTitles:nil];
        [alert show];
    }

}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    switch (result) {
        case MessageComposeResultCancelled:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"I Like It" message:@"User cancelled sending the SMS"
                                                           delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
        }
            break;
        case MessageComposeResultFailed:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"I Like It" message:@"Error occured while sending the SMS"
                                                           delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
        }
            break;
        case MessageComposeResultSent:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"I Like It" message:@"SMS sent successfully..!"
                                                           delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
        }
            break;
        default:
            break;
    }

    [self dismissModalViewControllerAnimated:YES];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-12 23:20:12

我相信如果你在模拟器中运行它,你会得到错误,因为它没有sms。我在模拟器中得到相同的错误,但如果我连接到我的手机,它可以正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10135258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档