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
は決して表示されません。私は実際にMFMessageComposeViewController
がUILocalNotification
を使用せずにアプリ内に正しく表示されることを知っています。
通知を受け取って「表示」をクリックした直後に、私はMFMessageComposeViewController
を提示します。