iOS - 收到UILocalNotification后显示MFMessageComposeViewController

时间:2012-02-09 15:02:21

标签: ios cocoa-touch sms uilocalnotification

我需要在收到MFMessageComposeViewController后提出UILocalNotification

现在我有一个视图控制器让我们称之为ViewControllerA,它符合MFMessageComposeViewControllerDelegate。在ViewControllerA中,我设置了以下方法:

- (void)sendNow {

    MFMessageComposeViewController *mfMessageComposeVC = [[MFMessageComposeViewController alloc] init];

    if([MFMessageComposeViewController canSendText]) {

        DLog(@"Can send text");

        mfMessageComposeVC.recipients = self.numbers;
        mfMessageComposeVC.body = self.message;
        mfMessageComposeVC.messageComposeDelegate = self;
        [self presentModalViewController:mfMessageComposeVC animated:YES];
    }   
}

所以当我从AppDelegate收到UILocalNotification时,我设置了以下方法:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

    DLog(@"Notification Body: %@", notification.alertBody);
    DLog(@"%@", notification.userInfo);

    //application.applicationIconBadgeNumber = 0;

    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateInactive) {

        // Application was in the background when notification was delivered.

        ViewControllerA *vcA = [[ViewControllerA alloc] initWithNibName:nil bundle:nil];
        vcA.messageData = [NSArray arrayWithArray:self.messageData];    
        [vcA sendNow];

        //[remindersNavigationController pushViewController:reminderDetailsVC animated:NO];

    } else {

        // Application is currently running, Alert the user with a UIAlertView that he has scheduled a message to be sent at this time, give him the option of Close and Send
    }
}

奇怪的是,当在模拟器中运行应用程序时,会弹出UIAlertView说“此设备无法发送文本”。此行为是预期的。但是当它在设备上运行时,它进入IF并记录“可以发送文本”,但MFMessageComposeViewController永远不会出现。事实上我知道MFMessageComposeViewController会在应用中正确呈现,而不会使用UILocalNotification

基本上在收到通知并点击“查看”后,我希望MFMessageComposeViewController出现。

1 个答案:

答案 0 :(得分:1)

    ViewControllerA *vcA = [[ViewControllerA alloc] initWithNibName:nil bundle:nil];
    vcA.messageData = [NSArray arrayWithArray:self.messageData];    
    [vcA sendNow];

vcA - 未添加(推送)到导航控制器或窗口或其他内容。 你在app delegate中有一个导航控制器变量吗?用它