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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值