2012-02-09 6 views
0

UILocalNotificationを受け取った後にMFMessageComposeViewControllerを提示する必要があります。iOS - UILocalNotificationを受け取った後にMFMessageComposeViewControllerを表示

今私はビューコントローラをMFMessageComposeViewControllerDelegateに準拠するViewControllerAと呼ぶことにしましょう。私はAppDelegateからUILocalNotificationを受信したとき、私はセットアップに次のメソッドを持っているので、

- (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]; 
    } 
} 

ViewControllerAで、私はセットアップに次のメソッドを持っている

- (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は決して表示されません。私は実際にMFMessageComposeViewControllerUILocalNotificationを使用せずにアプリ内に正しく表示されることを知っています。

通知を受け取って「表示」をクリックした直後に、私はMFMessageComposeViewControllerを提示します。

答えて

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

vcA - ナビゲーションコントローラまたはウィンドウなどに追加されません(プッシュ)。 アプリケーションデリゲートにnavコントローラ変数がありますか?それを使用する

関連する問題