//获取手机语言
-(NSString *)toObtainLanguage
{
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
NSArray * allLanguages = [defaults objectForKey:@"AppleLanguages"];
NSString * preferredLang = [allLanguages objectAtIndex:0];
return preferredLang;
}
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{//zh-Hans-CN简体中文
//en-CN 英文
//zh-Hant-CN繁体中文
//zh-TW 台湾
//zh-HK 香港
NSString *languageStr = [self toObtainLanguage];
if([languageStr isEqualToString:@”zh-Hans”])
{
[[NSUserDefaults standardUserDefaults] setObject:@”zh-Hans.lproj/Localizable” forKey:@”iPhone_languager”];
}
else if ([languageStr isEqualToString:@”zh-Hant-CN”] || [languageStr isEqualToString:@”zh-HK”] || [languageStr isEqualToString:@”zh-TW”])
{
[[NSUserDefaults standardUserDefaults] setObject:@”zh-Hant.lproj/Localizable” forKey:@”iPhone_languager”];
}
else
{
[[NSUserDefaults standardUserDefaults] setObject:@”en.lproj/Localizable” forKey:@”iPhone_languager”];
}//友盟统计初始化设置
[self umengConfiguration];//友盟分享初始化设置
// [self umengSetShare];//shareSDK分享设置
[self mobSetShare];//app 启动时,检查更新
[self checkAppToUpdate];if(CURRENT_VERSION>=8.0){//8.0以后使用这种方法来注册推送通知
[[UIApplication sharedApplication] registerForRemoteNotifications];UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}else{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
}//InstallUncaughtExceptionHandler();
//[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(tapReceivedNotificationHandler:)
name:kMPNotificationViewTapReceivedNotification
object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveRemoteMessage:) name:RECEIVE_REMOTE_MESSAGE object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ack_receiveRemoteMessage:) name:ACK_RECEIVE_REMOTE_MESSAGE object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSessionIdError:) name:NOTIFICATION_ON_SESSION_ERROR object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReceiveAlarmMessage:) name:RECEIVE_ALARM_MESSAGE object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReceiveDoorbellAlarmMessage:) name:RECEIVE_DOORBELL_ALARM_MESSAGE object:nil];
[AppDelegate getAppVersion];self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.networkStatus = ReachableViaWWAN;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
NSString *remoteHostName = @”www.baidu.com”;[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[[Reachability reachabilityWithHostName:remoteHostName] startNotifier];
//判断用户是否登录状态
if([UDManager isLogin]){MainController *mainController = [[MainController alloc] init]; self.mainController = mainController;
// NSString *lacalFlag = [[NSUserDefaults standardUserDefaults] objectForKey:@”AppStartInfoFlag”];
// if (!lacalFlag) {//first launching app(其实没必要判断,第一次只在进入登录界面时发生)
self.window.rootViewController = self.mainController;
// }else{
// self.window.rootViewController = [[[LaunchImageTransition alloc] initWithViewController:self.mainController animation:UIModalTransitionStyleCrossDissolve] autorelease];
// }
[mainController release];
LoginResult *loginResult = [UDManager getLoginInfo];
[[NetManager sharedManager] getAccountInfo:loginResult.contactId sessionId:loginResult.sessionId callBack:^(id JSON){
AccountResult *accountResult = (AccountResult*)JSON;
if(accountResult.error_code==NET_RET_GET_ACCOUNT_SUCCESS){
loginResult.email = accountResult.email;
loginResult.phone = accountResult.phone;
loginResult.countryCode = accountResult.countryCode;
[UDManager setLoginInfo:loginResult];
}
}];
}else{
LoginController *loginController = [[LoginController alloc] init];
AutoNavigation *mainController = [[AutoNavigation alloc] initWithRootViewController:loginController];
// NSString *lacalFlag = [[NSUserDefaults standardUserDefaults] objectForKey:@”AppStartInfoFlag”];
// if (!lacalFlag) {//first launching app
self.window.rootViewController = mainController;
// }else{
// self.window.rootViewController = [[[LaunchImageTransition alloc] initWithViewController:mainController animation:UIModalTransitionStyleCrossDissolve] autorelease];
// }
[loginController release];
[mainController release];
}
[self.window makeKeyAndVisible];
//状态栏的灰色view(区分导航栏)
self.navigationBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 20)];
self.navigationBar.backgroundColor = [UIColor blackColor];
self.navigationBar.alpha = 0.2;
// [self.window addSubview:self.navigationBar];
[self.navigationBar release];
pragma mark 安嘉添加内容
//开启开程序动画
UIView *view = [[StartTheAnimation alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
[self.window addSubview:view];
[self.window bringSubviewToFront:view];
[view release];
// [self networkStatus]
return YES;
}