2012-02-09 51 views
0

我需要在收到UILocalNotification後提供MFMessageComposeViewControlleriOS - 在收到UILocalNotification後呈現MFMessageComposeViewController

現在我有一個視圖控制器,我們稱之爲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
ViewControllerA *vcA = [[ViewControllerA alloc] initWithNibName:nil bundle:nil]; 
    vcA.messageData = [NSArray arrayWithArray:self.messageData];  
    [vcA sendNow]; 

vcA - 未添加(推送)到導航控制器或窗口或別的東西。 你在應用程序委託中有導航控制器變量嗎?使用它

相關問題