• iOS 中判断应用程序是否为第一次打开


    第一步:在AppDelegate中当应用启动完成后加入一下代码:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        //NSUserDefaults非常好用,并不需要用户在程序中设置NSUserDefaults的全局变量,需要在哪里使用NSUserDefaults的数据,那么就在哪里创建一个NSUserDefaults对象,然后进行读或者写操作。
        if (![[NSUserDefaults standardUserDefaults]boolForKey:@"everLaunched"]) {
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        }else{
             [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"]; 
        }
        // Override point for customization after application launch.
        return YES;
    }
    

     第二步:在ViewController的.m的ViewDidLoad方法中添加如下代码:

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
            // 这里判断是否第一次
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"第一次"
                                                          message:@"进入App"
                                                         delegate:self
                                                cancelButtonTitle:@"我知道了"
                                                otherButtonTitles:nil];
            [alert show];//使用UIAlertView显示应用是否为第一次启动
        }
    }
    

     此方法也可判断一个APP是否为第一次安装,可以设置跳转到相应的视图控制器

  • 相关阅读:
    HashMap,Hash优化与高效散列
    Dubbo Overview
    模板引擎 引自 《PHP核心技术与最佳实践》
    使用 phpStorm 开发
    使用 Zend_Studio 开发
    Symfony 2.0 认识Request, Response, Session, Cookie
    Symfony 建立一个Bundle
    Symfony 从路由认识它
    信鸽推送.net 服务端代码
    c#输出json,其中包含子json (可以含 无限级 子json)的方法思路
  • 原文地址:https://www.cnblogs.com/li--nan/p/4202501.html
Copyright © 2020-2023  润新知