versionManage.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. //
  2. // downloadTasks.m
  3. // sjvodios
  4. //
  5. // Created by on 11-11-28.
  6. // Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "versionManage.h"
  9. #import "AppDelegate.h"
  10. #import "JXConnection.h"
  11. #define AppURL @"https://itunes.apple.com/cn/app/%E8%A7%86%E9%85%B7im/id1160132242?mt=8"
  12. @implementation versionManage
  13. //remark = [NSString stringWithContentsOfFile:file encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000) error:nil];//改变乱码为中文
  14. @synthesize ftpHost;
  15. @synthesize ftpUsername;
  16. @synthesize ftpPassword;
  17. @synthesize buyUrl;
  18. @synthesize helpUrl;
  19. @synthesize softUrl;
  20. @synthesize shareUrl;
  21. @synthesize aboutUrl;
  22. @synthesize version;
  23. @synthesize theNewVersion;
  24. @synthesize versionRemark;
  25. @synthesize disableVersion;
  26. @synthesize message;
  27. @synthesize website;
  28. @synthesize backUrl;
  29. @synthesize apiUrl;
  30. @synthesize uploadUrl;
  31. @synthesize downloadUrl;
  32. @synthesize downloadAvatarUrl;
  33. @synthesize XMPPDomain;
  34. @synthesize meetingHost;
  35. @synthesize money_login;
  36. @synthesize money_share;
  37. @synthesize money_intro;
  38. @synthesize money_videoMeeting;
  39. @synthesize money_audioMeeting;
  40. @synthesize isCanChange;
  41. @synthesize videoMaxLen;
  42. @synthesize audioMaxLen;
  43. -(id)init{
  44. self = [super init];
  45. [self getDefaultValue];
  46. return self;
  47. }
  48. -(void)dealloc{
  49. self.apiUrl = nil;
  50. self.uploadUrl = nil;
  51. self.downloadAvatarUrl = nil;
  52. self.downloadUrl = nil;
  53. self.version = nil;
  54. self.ftpHost = nil;
  55. self.ftpUsername = nil;
  56. self.ftpPassword = nil;
  57. self.shareUrl = nil;
  58. self.buyUrl = nil;
  59. self.helpUrl = nil;
  60. self.aboutUrl = nil;
  61. self.XMPPDomain = nil;
  62. self.meetingHost = nil;
  63. self.buyUrl = nil;
  64. self.helpUrl = nil;
  65. self.website = nil;
  66. self.jitsiServer = nil;
  67. self.fileValidTime = nil;
  68. // [super dealloc];
  69. }
  70. -(void)showNewVersion{
  71. NSString *currentVersion = [self getVersion:version];
  72. if(theNewVersion != nil){
  73. if( [theNewVersion floatValue]> [currentVersion floatValue]){//发现新版本
  74. NSString* s=Localized(@"versionManage_Find");
  75. NSString *newVersion = [NSString stringWithFormat:@"%@",theNewVersion];
  76. NSString *temp = nil;
  77. NSMutableArray *array = [NSMutableArray array];
  78. for(int i =0; i < [newVersion length]; i++) {
  79. temp = [newVersion substringWithRange:NSMakeRange(i, 1)];
  80. [array addObject:temp];
  81. }
  82. newVersion = [array componentsJoinedByString:@"."];
  83. s = [NSString stringWithFormat:@"%@:%@",Localized(@"versionManage_Find"),newVersion];
  84. UIAlertController * alert = [UIAlertController alertControllerWithTitle:Localized(@"versionManage_Find") message:s preferredStyle:UIAlertControllerStyleAlert];
  85. UIAlertAction * action = [UIAlertAction actionWithTitle:Localized(@"JX_Update") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  86. if (self.appleId.length > 0 || self.iosAppUrl.length > 0) {
  87. //转跳升级
  88. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.iosAppUrl.length > 0 ? self.iosAppUrl : [NSString stringWithFormat:@"https://itunes.apple.com/cn/app/%%E8%%A7%86%E9%85%B7im/id%@?mt=8",self.appleId]]];
  89. }else {
  90. if(g_config.block)
  91. g_config.block();
  92. }
  93. }];
  94. UIAlertAction * actionCancel = [UIAlertAction actionWithTitle:Localized(@"JX_Cencal") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  95. if(g_config.block)
  96. g_config.block();
  97. }];
  98. [alert addAction:action];
  99. [alert addAction:actionCancel];
  100. [g_App.window.rootViewController presentViewController:alert animated:YES completion:nil];
  101. }else{
  102. if(g_config.block)
  103. g_config.block();
  104. }
  105. }
  106. }
  107. //版本已被禁用
  108. -(void)showDisableUse{
  109. // NSString* s=[NSString stringWithFormat:@"%@;",version];
  110. // if(disableVersion)
  111. // if( [disableVersion rangeOfString:s].location != NSNotFound )
  112. // [g_App showAlert:Localized(@"versionManage_Sorry")];
  113. NSString *banVer = [g_default objectForKey:@"ban_current_version"];
  114. if (!banVer || ![self.iosDisable isEqualToString:banVer]) {
  115. [g_default setObject:self.iosDisable forKey:@"ban_current_version"];
  116. }
  117. NSString *curVersion = [self.version stringByReplacingOccurrencesOfString:@"." withString:@""];
  118. NSString *banVersion = [self.iosDisable stringByReplacingOccurrencesOfString:@"." withString:@""];
  119. if ([curVersion intValue] <= [banVersion intValue]) {
  120. UIAlertController *alert = [UIAlertController alertControllerWithTitle:Localized(@"versionManage_Find") message:Localized(@"JX_BanUserCurrentVersion") preferredStyle:UIAlertControllerStyleAlert];
  121. // UIAlertAction *action = [UIAlertAction actionWithTitle:Localized(@"JX_Confirm") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  122. // //转跳升级
  123. // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:AppURL]];
  124. // }];
  125. // [alert addAction:action];
  126. [g_App.window.rootViewController presentViewController:alert animated:NO completion:nil];
  127. }
  128. }
  129. -(void)showServerMsg{
  130. // message = @"通知:新版本";
  131. if([message length]<=0)
  132. return;
  133. NSString* s=[docFilePath stringByAppendingPathComponent:@"messages.txt"];
  134. @try {
  135. if([[NSFileManager defaultManager]fileExistsAtPath:s])
  136. _msg = [[NSMutableDictionary alloc] initWithContentsOfFile:s];
  137. if(_msg == nil)
  138. _msg = [[NSMutableDictionary alloc]init];
  139. if([_msg objectForKey:message]==nil){
  140. [g_App showAlert:message];
  141. [_msg setObject:@"1" forKey:message];
  142. [_msg writeToFile:s atomically:YES];
  143. }
  144. // [_msg release];
  145. }
  146. @catch (NSException *exception) {
  147. }
  148. }
  149. - (void)getDataWithDict:(NSDictionary *)dict {
  150. g_App.isShowRedPacket = [dict objectForKey:@"displayRedPacket"];
  151. g_App.isShowApplyForWithdrawal = [dict objectForKey:@"isOpenWithdrawlApply"];
  152. g_App.isOpenActivity = [dict objectForKey:@"isOpenActivity"];
  153. g_App.activityUrl = [dict objectForKey:@"activityUrl"];
  154. g_App.activityName = [dict objectForKey:@"activityName"];
  155. // g_App.isShowRedPacket = [NSString stringWithFormat:@"0"];
  156. NSDictionary* p = [dict objectForKey:@"ios"];
  157. self.theNewVersion = [dict objectForKey:@"iosVersion"];
  158. self.versionRemark = [p objectForKey:@"versionRemark"];
  159. self.disableVersion = [p objectForKey:@"disableVersion"];
  160. self.message = [p objectForKey:@"message"];
  161. p = [dict objectForKey:@"money"];
  162. self.money_audioMeeting = [[p objectForKey:@"audioMeeting"] intValue];
  163. self.money_videoMeeting = [[p objectForKey:@"videoMeeting"] intValue];
  164. self.money_intro = [[p objectForKey:@"intro"] intValue];
  165. self.money_login = [[p objectForKey:@"login"] intValue];
  166. self.money_share = [[p objectForKey:@"share"] intValue];
  167. self.videoMaxLen = [[p objectForKey:@"videoMaxLen"] intValue];
  168. self.audioMaxLen = [[p objectForKey:@"audioMaxLen"] intValue];
  169. self.isCanChange = [[p objectForKey:@"isCanChange"] boolValue];
  170. p = dict;
  171. if([p objectForKey:@"ftpHost"])
  172. self.ftpHost = [p objectForKey:@"ftpHost"];
  173. if([p objectForKey:@"ftpUsername"])
  174. self.ftpUsername = [p objectForKey:@"ftpUsername"];
  175. if([p objectForKey:@"ftpPassword"])
  176. self.ftpPassword = [p objectForKey:@"ftpPassword"];
  177. if([p objectForKey:@"backUrl"])
  178. self.backUrl = [p objectForKey:@"resumeBaseUrl"];
  179. if([p objectForKey:@"buyUrl"])
  180. self.buyUrl = [p objectForKey:@"buyUrl"];
  181. if([p objectForKey:@"helpUrl"])
  182. self.helpUrl = [p objectForKey:@"helpUrl"];
  183. if([p objectForKey:@"softUrl"])
  184. self.softUrl = [p objectForKey:@"softUrl"];
  185. if([p objectForKey:@"shareUrl"])
  186. self.shareUrl = [p objectForKey:@"shareUrl"];
  187. if([p objectForKey:@"uploadUrl"]) {
  188. self.uploadUrl = [p objectForKey:@"uploadUrl"];
  189. [share_defaults setObject:self.uploadUrl forKey:kUploadUrl];
  190. }
  191. if([p objectForKey:@"downloadUrl"])
  192. self.downloadUrl = [p objectForKey:@"downloadUrl"];
  193. if([p objectForKey:@"downloadAvatarUrl"]) {
  194. self.downloadAvatarUrl = [p objectForKey:@"downloadAvatarUrl"];
  195. [share_defaults setObject:self.downloadAvatarUrl forKey:kDownloadAvatarUrl];
  196. }
  197. if([p objectForKey:@"XMPPDomain"]){
  198. self.XMPPDomain = [p objectForKey:@"XMPPDomain"];
  199. }
  200. if([p objectForKey:@"XMPPHost"]){
  201. self.XMPPHost = [p objectForKey:@"XMPPHost"];
  202. }
  203. if([p objectForKey:@"meetingHost"]){
  204. self.meetingHost = [p objectForKey:@"meetingHost"];
  205. }
  206. if([p objectForKey:@"website"])
  207. self.website = [p objectForKey:@"website"];
  208. if ([p objectForKey:@"jitsiServer"]) {
  209. self.jitsiServer = [p objectForKey:@"jitsiServer"];
  210. }
  211. if ([p objectForKey:@"fileValidTime"]) {
  212. self.fileValidTime = [p objectForKey:@"fileValidTime"];
  213. }
  214. if ([p objectForKey:@"XMPPTimeout"]) {
  215. self.XMPPTimeout = [[p objectForKey:@"XMPPTimeout"] intValue];
  216. }
  217. if ([p objectForKey:@"xmppPingTime"]) {
  218. self.XMPPPingTime = [[p objectForKey:@"xmppPingTime"] intValue];
  219. }
  220. if ([p objectForKey:@"isOpenSMSCode"]) {
  221. self.isOpenSMSCode = [p objectForKey:@"isOpenSMSCode"];
  222. }
  223. if ([p objectForKey:@"isOpenReceipt"]) {
  224. self.isOpenReceipt = [p objectForKey:@"isOpenReceipt"];
  225. }
  226. if ([p objectForKey:@"iosDisable"]) {
  227. self.iosDisable = [p objectForKey:@"iosDisable"];
  228. }
  229. if ([p objectForKey:@"isOpenCluster"]) {
  230. self.isOpenCluster = [p objectForKey:@"isOpenCluster"];
  231. }
  232. if ([p objectForKey:@"appleId"]) {
  233. self.appleId = [p objectForKey:@"appleId"];
  234. }
  235. if ([p objectForKey:@"companyName"]) {
  236. self.companyName = [p objectForKey:@"companyName"];
  237. }
  238. if ([p objectForKey:@"copyright"]) {
  239. self.copyright = [p objectForKey:@"copyright"];
  240. }
  241. if ([p objectForKey:@"hideSearchByFriends"]) {
  242. self.hideSearchByFriends = [p objectForKey:@"hideSearchByFriends"];
  243. }
  244. if ([p objectForKey:@"nicknameSearchUser"]) {
  245. self.nicknameSearchUser = [p objectForKey:@"nicknameSearchUser"];
  246. }
  247. if ([p objectForKey:@"regeditPhoneOrName"]) {
  248. self.regeditPhoneOrName = [p objectForKey:@"regeditPhoneOrName"];
  249. }
  250. if ([p objectForKey:@"registerInviteCode"]) {
  251. self.registerInviteCode = [p objectForKey:@"registerInviteCode"];
  252. }
  253. if ([p objectForKey:@"isCommonFindFriends"]) {
  254. self.isCommonFindFriends = [p objectForKey:@"isCommonFindFriends"];
  255. }
  256. if ([p objectForKey:@"isCommonCreateGroup"]) {
  257. self.isCommonCreateGroup = [p objectForKey:@"isCommonCreateGroup"];
  258. }
  259. if ([p objectForKey:@"isOpenPositionService"]) {
  260. self.isOpenPositionService = [p objectForKey:@"isOpenPositionService"];
  261. }
  262. // [self performSelectorOnMainThread:@selector(showNewVersion) withObject:nil waitUntilDone:NO];
  263. if ([p objectForKey:@"headBackgroundImg"]) {
  264. self.headBackgroundImg = [p objectForKey:@"headBackgroundImg"];
  265. }
  266. if ([p objectForKey:@"isOpenAPNSorJPUSH"]) {
  267. self.isOpenAPNSorJPUSH = [p objectForKey:@"isOpenAPNSorJPUSH"];
  268. }
  269. if ([p objectForKey:@"privacyPolicyPrefix"]) {
  270. self.privacyPolicyPrefix = [p objectForKey:@"privacyPolicyPrefix"];
  271. }
  272. if ([p objectForKey:@"iosAppUrl"]) {
  273. self.iosAppUrl = [p objectForKey:@"iosAppUrl"];
  274. }
  275. if ([p objectForKey:@"isOpenRoomSearch"]) {
  276. self.isOpenRoomSearch = [p objectForKey:@"isOpenRoomSearch"];
  277. }
  278. // 热门应用
  279. if ([p objectForKey:@"popularAPP"]) {
  280. SBJsonParser * resultParser = [[SBJsonParser alloc] init] ;
  281. id resultObject = [resultParser objectWithString:[p objectForKey:@"popularAPP"]];
  282. self.popularAPP = (NSDictionary *)resultObject;
  283. }
  284. if ([p objectForKey:@"address"]) {
  285. self.isChina = [[p objectForKey:@"address"] isEqualToString:@"CN"];
  286. }
  287. if ([p objectForKey:@"isOpenOnlineStatus"]) {
  288. self.isOpenOnlineStatus = [p objectForKey:@"isOpenOnlineStatus"];
  289. }
  290. if ([p objectForKey:@"videoLength"]) {
  291. self.videoLength = [p objectForKey:@"videoLength"];
  292. }
  293. if ([p objectForKey:@"enableMpModule"]) {
  294. self.enableMpModule = [p objectForKey:@"enableMpModule"];
  295. }
  296. if ([p objectForKey:@"showContactsUser"]) {
  297. self.showContactsUser = [p objectForKey:@"showContactsUser"];
  298. }
  299. if ([p objectForKey:@"enablePayModule"]) {
  300. self.enablePayModule = [p objectForKey:@"enablePayModule"];
  301. }
  302. }
  303. -(void)didReceive:(NSDictionary*)dict{
  304. @try {
  305. // 默认值赋值时,getDataWithDict方法中不赋值apiUrl
  306. if([dict objectForKey:@"apiUrl"]){
  307. self.apiUrl = [dict objectForKey:@"apiUrl"];
  308. [share_defaults setObject:self.apiUrl forKey:kApiUrl];
  309. }
  310. [self getDataWithDict:dict];
  311. [self showDisableUse];
  312. [self showServerMsg];
  313. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  314. [self showNewVersion];
  315. });
  316. //[self getNewVersion:version];
  317. // 保存这一次成功的IP
  318. [g_default setObject:self.apiUrl forKey:kLastApiUrl];
  319. [g_default synchronize];
  320. }
  321. @catch (NSException *exception){
  322. }
  323. @finally {
  324. }
  325. }
  326. //转换格式进行对比
  327. - (NSString *)getVersion:(NSString *) phoneVersion{
  328. NSArray * numberArr = [phoneVersion componentsSeparatedByString:@"."];
  329. NSString * numberVersion = [numberArr componentsJoinedByString:@""];
  330. // version = [numberVersion substringToIndex:3];
  331. return [numberVersion substringToIndex:numberVersion.length];
  332. }
  333. - (NSString *)getConfigDefault:(NSString *)url {
  334. NSString *configUrlStr = [NSString string];
  335. // 获取config默认值 (先网页上调config 接口获取值后,到http://www.bejson.com/ 转译json,则获取configUrlStr)
  336. return configUrlStr;
  337. }
  338. -(void)getDefaultValue{
  339. self.version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  340. NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:SERVER_LIST_DATA];
  341. if (array.firstObject) {
  342. // self.apiUrl = array.firstObject;
  343. self.apiUrl = [NSString stringWithFormat:@"http://%@:8092/config", APIURL]; // 新socket
  344. // self.apiUrl = [NSString stringWithFormat:@"http://%@:3001/config", testAPIURL]; // 新socket
  345. }else {
  346. self.apiUrl = [NSString stringWithFormat:@"http://%@:8092/config", APIURL]; // 新socket
  347. // self.apiUrl = [NSString stringWithFormat:@"http://%@:3001/config", testAPIURL]; // 新socket
  348. array = [[NSMutableArray alloc] initWithObjects:self.apiUrl, nil];
  349. [array writeToFile:SERVER_LIST_DATA atomically:YES];
  350. //保存一次默认apiUrl
  351. [g_default setObject:self.apiUrl forKey:kLastApiUrl];
  352. [g_default synchronize];
  353. }
  354. NSString *configUrlStr = [self getConfigDefault:apiUrl];
  355. // json 转 字典
  356. SBJsonParser *json = [[SBJsonParser alloc] init];
  357. NSDictionary *dict = [json objectWithString:configUrlStr];
  358. // 设置默认值
  359. [self getDataWithDict:[dict objectForKey:@"data"]];
  360. self.XMPPTimeout = 180; //xmpp超时时间 默认值180
  361. self.XMPPPingTime = 72; //xmpp ping时间间隔 默认值72
  362. }
  363. @end