如何在发送短信后手动返回应用程序

时间:2014-11-19 14:08:26

标签: ios objective-c iphone xcode sms

发送短信后,我会收到短信反馈。我复制了它,我想粘贴到应用程序中。但是我无法返回应用程序 - “取消”按钮变为灰色 - 不活动。

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {

    switch (result)
    {
        case MessageComposeResultCancelled:
            NSLog(@"Result: canceled");
             [self dismissViewControllerAnimated:YES completion:nil];
            break;
        case MessageComposeResultSent:
            NSLog(@"Result: sent");
            break;
        case MessageComposeResultFailed:
            NSLog(@"Result: failed");
            break;
        default:
            NSLog(@"Result: not sent");
            break;
    }

 //   [self dismissViewControllerAnimated:YES completion:nil];

}
-(void)sms{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init] ;
    if([MFMessageComposeViewController canSendText])
    {
        controller.body = @"message";
        controller.recipients = [NSArray arrayWithObjects:@"12344321", nil];
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:nil];
    }

}

1 个答案:

答案 0 :(得分:4)

您需要取消注释MFMessageComposeViewController 这应该有效,并会通过驳回switch statement并根据- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result中的tableImageArray行动将您带回应用程序。