简体   繁体   English

iOS –收到UILocalNotification后显示MFMessageComposeViewController

[英]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.

相关问题 如何在 mfmessagecomposeviewcontroller 中更改导航栏的颜色,同时在 ios 9 中显示它 - How to change color of navigation bar in mfmessagecomposeviewcontroller while presenting it in ios 9 呈现MFMessageComposeViewController然后将其关闭后,呈现视图无法正确显示 - Presenting view not appearing properly after MFMessageComposeViewController is presented and then dismissed 呈现MFMessageComposeViewController的图形问题 - Graphic issue presenting MFMessageComposeViewController 解雇并呈现MFMessageComposeViewController - Dismissing and Presenting MFMessageComposeViewController 发布使用iOS6解雇/重新呈现MFMessageComposeViewController,但使用iOS5则很好 - Issue dismissing/ re-presenting MFMessageComposeViewController with iOS6 but fine with iOS5 iOS10(Swift 3.0)中不推荐使用UILocalNotification接收功能 - UILocalNotification receiving function deprecated in iOS10 (Swift 3.0) 在iOS应用中触发UILocalNotification后的调用方法 - Call method after UILocalNotification fired in iOS app MFMessageComposeViewController消息消失,并在按下发送按钮后无法发送(iOS 7) - MFMessageComposeViewController messages disappear and fail to send after send button is pressed (iOS 7) UILocalNotification iOS 8 - UILocalNotification iOS 8 iOS 6 UILocalNotification - ios 6 UILocalNotification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM