IOS (APP 启动 相应处理)

时间:2023-12-04 21:40:32

APP 每次启动的入口都是通过:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

如果是用户自己启动的 launchOptions 是不带参数的,反之者有内容.

若是外部启动launchOptions KEY 一般有:

UIApplicationLaunchOptionsURLKey //通过openURL: 启动

UIApplicationLaunchOptionsSourceApplicationKey //应用程序的bundle ID

UIApplicationLaunchOptionsRemoteNotificationKey //远程通知启动

UIApplicationLaunchOptionsLocalNotificationKey //本地通知启动

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{     NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];     if(apsInfo) {
       
      NSlog(@"%@",
apsInfo);
        return YES;
    }
    return YES;
}

一般 在APP 启动的时候会做激活网络、设置导航栏、注册用户代理、判断是否首次登录、启动动画

激活网络:

[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];

[[AFNetworkReachabilityManager sharedManager] startMonitoring];
设置导航栏:
  

//barItem背景颜色

[[UINavigationBar appearance] setBarTintColor:[UIColor hex:@"#222028"]];

//返回按钮颜色

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

[[UINavigationBar appearance] setTitleTextAttributes:@{

NSForegroundColorAttributeName:[UIColor whiteColor]

}

];

注册用户代理:

#import "sys/utsname.h"

- (void)registerUserAgent{

//区分客户端访问类型 是否是IOS、Android、Web端

struct utsname systemInfo;

uname(&systemInfo);

NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

NSString *userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], deviceString, [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)];

NSDictionary *dictionary = @{@"UserAgent" : userAgent};//User-Agent

[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

/*

UIWebView* tempWebView = [[UIWebView alloc] initWithFrame:CGRectZero];

NSString* userAgent = [tempWebView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];

//        NSLog(@"------%@",userAgent);

NSString *executableFile = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey];

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];

NSString *ua = [NSString stringWithFormat:@"%@ %@/%@", userAgent, executableFile,version];

//        NSLog(@"------%@",ua);

[[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent" : ua, @"User-Agent" : ua}];

NSLog(@"%@ ",ua);

*/

}

判断是否首次登录:
  

if ([Login isLogin]) {

[self setupTabViewController];

}else{

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

[self setupIntroductionViewController];

}

启动动画:

  

@weakify(self);

[startView startAnimationWithCompletionBlock:^(EaseStartView *easeStartView) {

@strongify(self);

//启动动画完成后 做注册推送、注册统计、推送反馈

[self completionStartAnimationWithOptions:launchOptions];

}];