You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by GitBox <gi...@apache.org> on 2018/11/19 11:39:36 UTC

[GitHub] HJaycee closed pull request #1770: [iOS]Fix bug: register service method needs a callback

HJaycee closed pull request #1770: [iOS]Fix bug: register service method needs a callback
URL: https://github.com/apache/incubator-weex/pull/1770
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h
index 5e7b1e7db6..b1f6e8bac0 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h
@@ -79,8 +79,10 @@
  *
  * @param serviceScript service js code to invoke
  *
+ * @param completion completion callback
+ *
  */
-+ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options;
++ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion;
 
 /**
  * @abstract Registers a component for a given name, options and js url
@@ -91,8 +93,10 @@
  *
  * @param serviceScriptUrl The service url to register
  *
+ * @param completion completion callback
+ *
  */
-+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options;
++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion;
 
 /**
  * @abstract Registers a component for a given name, options and js code
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
index 91fdd90132..52f9c77d3b 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
@@ -152,14 +152,14 @@ + (void)registerComponent:(NSString *)name withClass:(Class)clazz withProperties
 
 
 # pragma mark Service Register
-+ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options
++ (void)registerService:(NSString *)name withScript:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void (^)(BOOL))completion
 {
-    [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options];
+    [[WXSDKManager bridgeMgr] registerService:name withService:serviceScript withOptions:options completion:completion];
 }
 
-+ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options
++ (void)registerService:(NSString *)name withScriptUrl:(NSURL *)serviceScriptUrl WithOptions:(NSDictionary *)options completion:(void (^)(BOOL))completion
 {
-    [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options];
+    [[WXSDKManager bridgeMgr] registerService:name withServiceUrl:serviceScriptUrl withOptions:options completion:completion];
 }
 
 + (void)unregisterService:(NSString *)name
@@ -339,7 +339,7 @@ + (void)restartWithScript:(NSString*)script
         NSString *serviceName = [service objectForKey:@"name"];
         NSString *serviceScript = [service objectForKey:@"script"];
         NSDictionary *serviceOptions = [service objectForKey:@"options"];
-        [WXSDKEngine registerService:serviceName withScript:serviceScript withOptions:serviceOptions];
+        [WXSDKEngine registerService:serviceName withScript:serviceScript withOptions:serviceOptions completion:nil];
     }
 }
 
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h
index 163475bd81..3dc25296d7 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.h
@@ -90,8 +90,9 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void));
  *  @param name      :   service name
  *  @param serviceScript    :   script code
  *  @param options   :   service options
+ *  @param completion   :   completion callback
  **/
-- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options;
+- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion;
 
 
 /**
@@ -99,9 +100,10 @@ extern void WXPerformBlockOnBridgeThread(void (^block)(void));
  *  @param name         :   service name
  *  @param serviceScriptUrl    :   script url
  *  @param options      :   service options
+ *  @param completion   :   completion callback
  **/
 
--(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options;
+-(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion;
 
 /**
  *  Unregister JS service Script
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
index 3a9e27e020..7f52c22455 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
@@ -255,28 +255,36 @@ - (JSValue *)callJSMethodWithResult:(WXCallJSMethod *)method
     return value;
 }
 
--(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options
+-(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void (^)(BOOL))completion
 {
-    if (!name || !serviceScriptUrl || !options) return;
+    if (!name || !serviceScriptUrl || !options) {
+        if (completion) completion(NO);
+        return;
+    }
+    
     __weak typeof(self) weakSelf = self;
     WXResourceRequest *request = [WXResourceRequest requestWithURL:serviceScriptUrl resourceType:WXResourceTypeServiceBundle referrer:@"" cachePolicy:NSURLRequestUseProtocolCachePolicy];
     WXResourceLoader *serviceBundleLoader = [[WXResourceLoader alloc] initWithRequest:request];;
     serviceBundleLoader.onFinished = ^(WXResourceResponse *response, NSData *data) {
         __strong typeof(weakSelf) strongSelf = weakSelf;
         NSString *jsServiceString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-        [strongSelf registerService:name withService:jsServiceString withOptions:options];
+        [strongSelf registerService:name withService:jsServiceString withOptions:options completion:completion];
     };
     
     serviceBundleLoader.onFailed = ^(NSError *loadError) {
         WXLogError(@"No script URL found");
+        if (completion) completion(NO);
     };
     
     [serviceBundleLoader start];
 }
 
-- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options
+- (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void (^)(BOOL))completion
 {
-    if (!name || !serviceScript || !options) return;
+    if (!name || !serviceScript || !options) {
+        if (completion) completion(NO);
+        return;
+    }
     
     NSString *script = [WXServiceFactory registerServiceScript:name withRawScript:serviceScript withOptions:options];
     
@@ -285,6 +293,7 @@ - (void)registerService:(NSString *)name withService:(NSString *)serviceScript w
         // save it when execute
         [WXDebugTool cacheJsService:name withScript:serviceScript withOptions:options];
         [weakSelf.bridgeCtx executeJsService:script withName:name];
+        if (completion) completion(YES);
     });
 }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services