1
This commit is contained in:
@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
typedef void(^KBLoginCompletion)(BOOL success, NSError * _Nullable error);
|
||||
typedef void(^KBRegisterCompletion)(BOOL success, NSError * _Nullable error);
|
||||
typedef void(^KBVerifyMailCompletion)(BOOL success, NSError * _Nullable error);
|
||||
typedef void(^KBAppUpdateCompletion)(NSDictionary * _Nullable data, NSError * _Nullable error);
|
||||
|
||||
@interface KBLoginVM : NSObject
|
||||
|
||||
@@ -42,6 +43,9 @@ typedef void(^KBVerifyMailCompletion)(BOOL success, NSError * _Nullable error);
|
||||
/// 是否已登录:由 KBAuthManager 判断(是否存在有效 token)
|
||||
- (BOOL)isLoggedIn;
|
||||
|
||||
/// 检查是否需要更新
|
||||
- (void)checkAppUpdateWithCompletion:(KBAppUpdateCompletion)completion;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -164,6 +164,15 @@
|
||||
}];
|
||||
}
|
||||
|
||||
/// 检查更新
|
||||
- (void)checkAppUpdateWithCompletion:(KBAppUpdateCompletion)completion {
|
||||
NSDictionary *params = [self kb_appUpdateParams];
|
||||
[[KBNetworkManager shared] POST:API_APP_CHECK_UPDATE jsonBody:params headers:nil autoShowBusinessError:NO completion:^(NSDictionary * _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
if (error) { if (completion) completion(nil, error); return; }
|
||||
if (completion) completion(jsonOrData, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)kb_syncKeyboardCharactersAfterLogin {
|
||||
@@ -228,4 +237,63 @@
|
||||
return @(value);
|
||||
}
|
||||
|
||||
- (NSDictionary *)kb_appUpdateParams {
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
params[@"appId"] = @"main";
|
||||
params[@"platform"] = @"ios";
|
||||
params[@"channel"] = @"AppStore";
|
||||
NSString *shortVersion = [self kb_bundleShortVersion];
|
||||
if (shortVersion.length) {
|
||||
params[@"clientVersionName"] = shortVersion;
|
||||
}
|
||||
NSString *buildNumber = [self kb_bundleBuildNumber];
|
||||
if (buildNumber.length) {
|
||||
params[@"buildNumber"] = buildNumber;
|
||||
}
|
||||
NSNumber *versionCode = [self kb_versionCodeFromBuildNumber:buildNumber shortVersion:shortVersion];
|
||||
// if (versionCode) {
|
||||
params[@"clientVersionCode"] = @1;
|
||||
// }
|
||||
return params;
|
||||
}
|
||||
|
||||
- (nullable NSString *)kb_bundleShortVersion {
|
||||
id obj = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
||||
if ([obj isKindOfClass:NSString.class]) { return (NSString *)obj; }
|
||||
if ([obj respondsToSelector:@selector(stringValue)]) { return [obj stringValue]; }
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (nullable NSString *)kb_bundleBuildNumber {
|
||||
id obj = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
|
||||
if ([obj isKindOfClass:NSString.class]) { return (NSString *)obj; }
|
||||
if ([obj respondsToSelector:@selector(stringValue)]) { return [obj stringValue]; }
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (nullable NSNumber *)kb_versionCodeFromBuildNumber:(nullable NSString *)buildNumber
|
||||
shortVersion:(nullable NSString *)shortVersion {
|
||||
NSString *digits = [self kb_digitsOnlyStringFromString:buildNumber];
|
||||
if (digits.length == 0) {
|
||||
digits = [self kb_digitsOnlyStringFromString:shortVersion];
|
||||
}
|
||||
if (digits.length == 0) { return nil; }
|
||||
long long value = digits.longLongValue;
|
||||
if (value <= 0) { return nil; }
|
||||
return @(value);
|
||||
}
|
||||
|
||||
- (nullable NSString *)kb_digitsOnlyStringFromString:(nullable NSString *)string {
|
||||
if (![string isKindOfClass:NSString.class] || string.length == 0) { return nil; }
|
||||
NSCharacterSet *set = [NSCharacterSet decimalDigitCharacterSet];
|
||||
NSMutableString *digits = [NSMutableString string];
|
||||
for (NSUInteger i = 0; i < string.length; i++) {
|
||||
unichar c = [string characterAtIndex:i];
|
||||
if ([set characterIsMember:c]) {
|
||||
[digits appendFormat:@"%C", c];
|
||||
}
|
||||
}
|
||||
return digits;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user