ios語言設置

//獲取手機語言
-(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;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章