此设备未启用短信

时间:2011-05-19 03:12:56

标签: iphone sms

我遵循了本教程:http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/  我收到提示“此设备上未启用短信”。

我已经在我的.h文件中导入了MessageUI框架,“MessageUI / MessageUI.h”和MFMessageComposeViewControllerDelegate。从我在网上看到的,人们似乎能够查看MFMessageComposeViewController。

//.h file
#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import <MessageUI/MessageUI.h>
...

@interface DateDetailsViewController : UIViewController <UIActionSheetDelegate, MFMessageComposeViewControllerDelegate, UINavigationControllerDelegate>
...

//.m file
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
    if([MFMessageComposeViewController canSendText])
    {
        controller.body = @"testing";
        controller.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321", 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:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Unknown Error"
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
        break;
    case MessageComposeResultSent:

        break;
    default:
        break;
}

[self dismissModalViewControllerAnimated:YES];
}

有什么我想念的吗?提前致谢。

1 个答案:

答案 0 :(得分:5)

MessageUI无法从模拟器发送短信。您的应用程序需要在带有短信服务的iPhone上运行。