美文网首页
域名国际化

域名国际化

作者: AlanQingHua | 来源:发表于2016-10-23 23:45 被阅读0次

域名国际化

一个app国际化的过程种避免的要做域名国家化的以便app能快速的访问

1 app第一次启动的时候的在有网的情况下会下载好每个时区对应域名的key,这个可以存在偏好设置中 ,我们在用这利用本地的域名做为key 偏好设置的中的域名的key 做为value 。

2 每次调接口的时候通过的这个域名下发的来找到每个地区对应的域名

3 域名下发 app启动的时候 执行sdk 封撞得 域名下发successed 回调

此时在 回到外面写一个数组

NSArray * const domainArray =@[kURL_serverLeCall_Login,kBaseURL_bindDevice,kBaseURL_accountPortrait,kBaseURL_feedback,kURL_bindStatus_phoneNumberWithLetvAccount ,kBaseURL_versionUpdate,kBaseURL_syncContact];

这个数据包含所有的域名

          [domainArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
      NSString *key  = (NSString*)obj;
      NSString  *plistPath =  [[NSBundle mainBundle] pathForResource:@"RealmName" ofType:@"plist"];
      NSDictionary  *cnDict  =[[NSDictionary alloc] initWithContentsOfFile:plistPath][@"cn"];
      NSString * region = cnDict[key];
      NSString * realName = [[LeCallManagerObject sharedManager ] realmNameWithRegion:region];
      if (realName !=nil) {
          [orignalDomainDict setObject:realName forKey:realName];
      }
  }];

遍历这个数组的时候把域名下发的国际化域名 加入的本地域名为key 下发域名与为value的字典里

在SDK回调里也写一个的遍历

[domainArray enumerateObjectsUsingBlock:^(id  _Nonnull obj,   NSUInteger idx, BOOL * _Nonnull stop) {
                   NSString *key  = (NSString*)obj;
                  NSString  *plistPath =  [[NSBundle mainBundle]   pathForResource:@"RealmName" ofType:@"plist"];
                  NSDictionary  *cnDict  =[[NSDictionary alloc] initWithContentsOfFile:plistPath][@"cn"];
                  NSString * region = cnDict[key];
                  NSString * realName = [[LeCallManagerObject sharedManager ] realmNameWithRegion:region];
                  
                  if (realName !=nil) {
                      [newDomainDict setObject:realName forKey:realName];
                  }
              }];

当两个字典一样的时候国际化域名不需要再掉SDK的在掉一个网络请求
不一样的时候在掉一次借口。 这样可以避免启动的时候每次都调用2次接口和数据库操作

相关文章

网友评论

      本文标题:域名国际化

      本文链接:https://www.haomeiwen.com/subject/tjbayttx.html