[英]iOS – Presenting MFMessageComposeViewController after receiving a UILocalNotification
I need to present a MFMessageComposeViewController
after receiving a UILocalNotification
. 我需要在收到MFMessageComposeViewController
之后提出UILocalNotification
。
Right now I have a view controller let's call it ViewControllerA
which conforms to the MFMessageComposeViewControllerDelegate
. 现在我有一个视图控制器,我们称它为ViewControllerA
,它符合MFMessageComposeViewControllerDelegate
。 In ViewControllerA
I have setup the following method: 在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];
}
}
So when I receive a UILocalNotification from the AppDelegate I have setup the following method: 因此,当我从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
}
}
The weird thing is that when running the app in the simulator it pops up a UIAlertView
saying "this device cannot send text". 奇怪的是,当在模拟器中运行应用程序时,它会弹出UIAlertView
“此设备无法发送文本”。 This behaviour is expected. 此行为是预期的。 But when running it on the device it goes inside the IF and logs "Can send text" but the MFMessageComposeViewController
is never presented. 但是,当在设备上运行它时,它将进入IF并记录“可以发送文本”,但是从不显示MFMessageComposeViewController
。 I know in fact that the MFMessageComposeViewController
will present itself properly in the app without using the UILocalNotification
. 我实际上知道MFMessageComposeViewController
会在应用程序中正确显示自己,而无需使用UILocalNotification
。
Basically just after receiving the notification and clicking "View" I want the MFMessageComposeViewController
to be presented. 基本上在收到通知并单击“查看”之后,我希望显示MFMessageComposeViewController
。
ViewControllerA *vcA = [[ViewControllerA alloc] initWithNibName:nil bundle:nil];
vcA.messageData = [NSArray arrayWithArray:self.messageData];
[vcA sendNow];
vcA - is not added (pushed) to nav controller or window or to something else. vcA-不会添加(推送)到导航控制器或窗口或其他内容。 Do you have a nav controller variable in app delegate? 您在应用程序委托中是否有导航控制器变量? use it 用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.