Skip to content

Commit c098951

Browse files
committed
更新第七章,与RN0.21版本同步
1 parent 6ed3724 commit c098951

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

第7章/version-component/CtripVersion/ReactVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <UIKit/UIKit.h>
10-
#import "RCTBridge.h"
10+
#import "RCTBridge+Private.h"
1111

1212
@interface ReactVersion : NSObject<RCTBridgeModule>
1313

第7章/version-component/CtripVersion/ReactVersion.m

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,26 @@ - (void)dealloc
6767
#pragma mark JS Method
6868

6969
RCT_EXPORT_METHOD(getCurrentJsVersion:(RCTPromiseResolveBlock)resolver
70-
rejecter:(RCTPromiseRejectBlock)rejecter)
70+
rejecter:(RCTPromiseRejectBlock)rejecter)
7171
{
7272
NSString *jsCodeVersion = [[NSUserDefaults standardUserDefaults] stringForKey:kCurrentReactJsCodeVersion] ?: __inAppVersion;
7373

7474
if (jsCodeVersion) {
7575
resolver(jsCodeVersion);
7676
} else {
77-
rejecter([NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can not get JS Version"]}]);
77+
rejecter(@"500", @"Can not get JS Version", [NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can not get JS Version"]}]);
7878
}
7979
}
8080

8181

8282
RCT_EXPORT_METHOD(getRemoteVersion:(RCTPromiseResolveBlock)resolver
83-
rejecter:(RCTPromiseRejectBlock)rejecter)
83+
rejecter:(RCTPromiseRejectBlock)rejecter)
8484
{
8585
NSURLRequest *configRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://***/version.config"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];
8686
NSURLSessionTask *configTask = [__URLSession dataTaskWithRequest:configRequest completionHandler:^(NSData * data, NSURLResponse * response, NSError * error) {
8787

8888
if (error) {
89-
rejecter(error);
89+
rejecter(@"500", @"Download error:request version.config failure", error);
9090
return;
9191
}
9292
@try {
@@ -95,20 +95,20 @@ - (void)dealloc
9595
NSDictionary *config= [NSJSONSerialization JSONObjectWithData:data options:0 error:&serilazationError];
9696

9797
if (serilazationError) {
98-
rejecter(serilazationError);
98+
rejecter(@"500", @"Convert NSData to JSON failure", serilazationError);
9999
return;
100100
}
101101

102102
NSString *remoteJsVersion = config[@"bundle_version"];
103103
if (remoteJsVersion) {
104104
resolver(remoteJsVersion);
105105
} else {
106-
rejecter([NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can not get JS Version"]}]);
106+
rejecter(@"500", @"Can not get JS Version", [NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can not get JS Version"]}]);
107107
}
108108

109109
}
110110
@catch (NSException *exception) {
111-
rejecter([NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: exception.reason}]);
111+
rejecter(@"500", exception.reason, [NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: exception.reason}]);
112112
}
113113

114114
}];
@@ -117,8 +117,8 @@ - (void)dealloc
117117

118118

119119
RCT_EXPORT_METHOD(updateVersion:(NSDictionary *)config
120-
resolver:(RCTPromiseResolveBlock)resolver
121-
rejecter:(RCTPromiseRejectBlock)rejecter)
120+
resolver:(RCTPromiseResolveBlock)resolver
121+
rejecter:(RCTPromiseRejectBlock)rejecter)
122122
{
123123

124124
@try {
@@ -133,7 +133,7 @@ - (void)dealloc
133133

134134
if (error || !location) {
135135
RCTLogWarn(@"Download error. %@",[error description]);
136-
rejecter(error);
136+
rejecter(@"500", [@"Download error! please check your server:%@" stringByAppendingString:request.URL.absoluteString], error);
137137
return;
138138
}
139139

@@ -146,21 +146,21 @@ - (void)dealloc
146146
RCTLogInfo(@"Update Js Code success");
147147
resolver(remoteJsVersion);
148148
} else {
149-
rejecter(ioError);
149+
rejecter(@"500", [NSString stringWithFormat:@"Copies the item at the %@ to %@ failure", [location resourceSpecifier], [ReactVersion pathForVersion:remoteJsVersion]], ioError);
150150
}
151151

152152
}];
153153
[downloadTask resume];
154154

155155
} else {
156-
rejecter([NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: @"don't need update"}]);
156+
rejecter(@"500", @"don't need update", [NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: @"don't need update"}]);
157157
}
158158

159159
}
160160
@catch (NSException *exception) {
161-
rejecter([NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: exception.reason}]);
161+
rejecter(@"500", exception.reason, [NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: exception.reason}]);
162162
}
163-
163+
164164

165165
}
166166

@@ -178,13 +178,13 @@ - (void)dealloc
178178
}
179179

180180
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
181-
rejecter([NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: @"no file exists"}]);
181+
rejecter(@"500", @"no file exists", [NSError errorWithDomain:ErrorDomain code:(500) userInfo:@{NSLocalizedDescriptionKey: @"no file exists"}]);
182182
return;
183183
}
184-
184+
185185
self.bridge.bundleURL = [NSURL fileURLWithPath:path];
186186
[self.bridge reload];
187-
187+
188188
}
189189

190190
#pragma -

0 commit comments

Comments
 (0)