HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 在显示来自viewDidload的警报之前显示来自app delegate的警报大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图通过parse.com文档中概述的app委托显示推送通知中包含的消息.

我遇到的问题是,在我的第一个视图控制器的viewdidload方法中,我提出了一个用户在使用应用程序之前必须看到的警报.

用户从viewdidload方法中看到警报后,如何从我的应用程序委托中调用方法

编辑:

所以,正如评论中所建议的那样,我添加一个全局变量,一旦我从我的ViewDidload方法显示警报,我就设置为true,但是我的appDelegate的通知警报仍然没有出现.

这是我的app delegate.m文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [Parse setApplicationId:@"xxxxxxxxxxxxxxxx"
                  clientKey:@"xxxxxxxxxxxx"];

    // Register for Push Notitications,if running iOS 8
    if ([application respondsToSELEctor:@SELEctor(registerUserNotificationSetTings:)]) {
        UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                        UIUserNotificationTypeBadge |
                                                        UIUserNotificationTypeSound);
        UIUserNotificationSetTings *setTings = [UIUserNotificationSetTings setTingsForTypes:userNotificationTypes
                                                                                 categories:nil];
        [application registerUserNotificationSetTings:setTings];
        [application registerForRemoteNotifications];
    } else {
        // Register for Push Notifications before iOS 8
        [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                         UIRemoteNotificationTypeAlert |
                                                         UIRemoteNotificationTypeSound)];
    }
    return YES;



    NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];


    if (Notification == truE) {
        if (![pushText  isEqual: @""]) {
            pushText = [[notificationPayload objectForKey:@"aps"] objectForKey:@"alert"];
            UIAlertView *alert_news = [[UIAlertView alloc] initWithtitle:NSLocalizedString(@"News","")
                                                                 message:pushText
                                                                delegate:nil
                                                       cancelButtontitle:@"Ok"
                                                       otherButtontitles: nil];
            [alert_news show];


            }
    }


}@H_301_22@ 
 

这是我的viewdidload方法

roadSafetyAppAppDelegate *AppDelegate;

- (void)viewDidLoad
{
        AppDelegate = (roadSafetyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
        [super viewDidLoad];

    // Do any additional setup after loading the view,typically from a nib.



    BACkgroundImage.alpha = 0.3;
    toRecipients = [[NSArray alloc]initWithObjects:@"records@sHellharbour.nsw.gov.au",nil];
    static int appCounter;
    if ( appCounter < 1   ) {
        UIAlertView *alert = [[UIAlertView alloc] initWithtitle:NSLocalizedString(@"Disclaimer","")
                                                        message:NSLocalizedString(@"Using a mobile phone whilst driving is against the law. Ensure that you are not behind the wheel when using this app.","")
                                                       delegate:nil
                                              cancelButtontitle:@"I agree to not use a mobile phone while driving"
                                              otherButtontitles: nil];
        [alert show];
        appCounter = appCounter+1;

       AppDelegate.NotificationAlert = @"1";
        AppDelegate.Notification = true;



    }

}@H_301_22@

解决方法

因为您希望在显示任何通知之前显示免责声明一次,并确保用户在同意按钮上看到并轻敲.你可以使用简单的本地通知来做到这一点.

在委托中(… didFinishLaunchingWithOptions

本图文内容来源于网友网络收集整理提供,作为学习参使用,版权属于原作者。

大佬总结

以上是大佬教程为你收集整理的ios – 在显示来自viewDidload的警报之前显示来自app delegate的警报全部内容,希望文章能够帮你解决ios – 在显示来自viewDidload的警报之前显示来自app delegate的警报所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。