我需要在收到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
出现。
答案 0 :(得分:1)
ViewControllerA *vcA = [[ViewControllerA alloc] initWithNibName:nil bundle:nil];
vcA.messageData = [NSArray arrayWithArray:self.messageData];
[vcA sendNow];
vcA - 未添加(推送)到导航控制器或窗口或其他内容。 你在app delegate中有一个导航控制器变量吗?用它