|
@@ -76,6 +76,11 @@
|
|
|
[KSNetworkAccessibleManager setAlertEnable:YES];
|
|
|
[KSNetworkAccessibleManager setStateDidUpdateNotifier:^(KSNetworkAccessibleState state) {
|
|
|
NSLog(@"setStateDidUpdateNotifier > %zd", state);
|
|
|
+ if (state == KSNetworkAccessible) {
|
|
|
+ if (self.isNeedUpdate) {
|
|
|
+ [self versionCheck];
|
|
|
+ }
|
|
|
+ }
|
|
|
}];
|
|
|
|
|
|
[KSNetworkAccessibleManager start];
|
|
@@ -236,39 +241,46 @@
|
|
|
|
|
|
- (void)versionCheck {
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
- [KSUpdateManager ks_updateWithAPPID:@"1626971149" withBundleId:nil block:^(NSString * _Nonnull currentVersion, NSString * _Nonnull storeVersion, NSString * _Nonnull openUrl, BOOL isUpdate) {
|
|
|
- if (isUpdate) {
|
|
|
-
|
|
|
- [KSNetworkingManager appVersionInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
|
|
|
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
|
|
|
-
|
|
|
- NSString *serviceVersion = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"version"];
|
|
|
- if ([serviceVersion isEqualToString:storeVersion] || [self isLowerVersionCompareLocalVersion:currentVersion serviceVersion:serviceVersion]) {
|
|
|
- // desc
|
|
|
- NSString *descMessage = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"description"];
|
|
|
- NSString *downloadUrl = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"downloadUrl"];
|
|
|
- // 如果没有配置
|
|
|
- if ([NSString isEmptyString:downloadUrl]) {
|
|
|
- downloadUrl = openUrl;
|
|
|
- }
|
|
|
- // 判断
|
|
|
- if ([[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"isForceUpdate"]) {
|
|
|
- self.isNeedUpdate = YES;
|
|
|
- [self showAlertWithMemo:storeVersion descMessage:descMessage isforce:YES openUrl:downloadUrl];
|
|
|
- }
|
|
|
- else {
|
|
|
- self.isNeedUpdate = NO;
|
|
|
- [self showAlertWithMemo:storeVersion descMessage:descMessage isforce:NO openUrl:downloadUrl];
|
|
|
+ [KSUpdateManager ks_updateWithAPPID:@"1626971149" withBundleId:nil block:^(BOOL isSuccess, NSString * _Nonnull currentVersion, NSString * _Nonnull storeVersion, NSString * _Nonnull openUrl, BOOL isUpdate) {
|
|
|
+ if (isSuccess) {
|
|
|
+ if (isUpdate) {
|
|
|
+
|
|
|
+ [KSNetworkingManager appVersionInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
|
|
|
+
|
|
|
+ NSString *serviceVersion = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"version"];
|
|
|
+ if ([serviceVersion isEqualToString:storeVersion] || [self isLowerVersionCompareLocalVersion:currentVersion serviceVersion:serviceVersion]) {
|
|
|
+ // desc
|
|
|
+ NSString *descMessage = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"description"];
|
|
|
+ NSString *downloadUrl = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"downloadUrl"];
|
|
|
+ // 如果没有配置
|
|
|
+ if ([NSString isEmptyString:downloadUrl]) {
|
|
|
+ downloadUrl = openUrl;
|
|
|
+ }
|
|
|
+ // 判断
|
|
|
+ if ([[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"isForceUpdate"]) {
|
|
|
+ self.isNeedUpdate = YES;
|
|
|
+ [self showAlertWithMemo:storeVersion descMessage:descMessage isforce:YES openUrl:downloadUrl];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.isNeedUpdate = NO;
|
|
|
+ [self showAlertWithMemo:storeVersion descMessage:descMessage isforce:NO openUrl:downloadUrl];
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
- } faliure:^(NSError * _Nonnull error) {
|
|
|
- [self showAlertWithMemo:storeVersion descMessage:@"全新版本上线了,赶快来体验吧!" isforce:NO openUrl:openUrl];
|
|
|
- }];
|
|
|
+ }
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ if ([self isLowerVersionCompareLocalVersion:currentVersion serviceVersion:storeVersion]) {
|
|
|
+ [self showAlertWithMemo:storeVersion descMessage:@"全新版本上线了,赶快来体验吧!" isforce:NO openUrl:openUrl];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ NSLog(@"当前版本%@,商店版本%@,不需要更新",currentVersion,storeVersion);
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
- NSLog(@"当前版本%@,商店版本%@,不需要更新",currentVersion,storeVersion);
|
|
|
+ self.isNeedUpdate = YES;
|
|
|
}
|
|
|
}];
|
|
|
});
|
|
@@ -441,9 +453,6 @@ didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
|
[self.timer invalidate];
|
|
|
self.timer = nil;
|
|
|
}
|
|
|
- if (self.isNeedUpdate) {
|
|
|
- [self versionCheck];
|
|
|
- }
|
|
|
[self checkConnectionStatus];
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"appBecomeActive" object:nil];
|
|
@@ -463,6 +472,9 @@ didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
|
|
// app启动或者app从后台进入前台都会调用这个方法
|
|
|
[JPUSHService resetBadge]; // 清空 JPush 服务器中存储的 badge 值
|
|
|
+ if (self.isNeedUpdate) {
|
|
|
+ [self versionCheck];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|