Repository: incubator-weex
Updated Branches:
  refs/heads/master cbfcf4ee4 -> bf61e99c3


[WEEX-289][iOS]post notice when instance jscontext created
* [iOS] bind instanceId to jscontext

close #1111


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/bf61e99c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/bf61e99c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/bf61e99c

Branch: refs/heads/master
Commit: bf61e99c3d8f82093d1c128d07ba894e99050b41
Parents: cbfcf4e
Author: xuyouyang <youyang....@alibaba-inc.com>
Authored: Thu Apr 12 17:31:28 2018 +0800
Committer: acton393 <zhangxing610...@gmail.com>
Committed: Thu Apr 19 19:42:13 2018 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK.xcodeproj/project.pbxproj       | 12 +++++++
 ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.h | 26 +++++++++++++++
 ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.m | 35 ++++++++++++++++++++
 ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m |  2 ++
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m   | 10 +++---
 ios/sdk/WeexSDK/Sources/Utility/WXDefine.h      |  2 ++
 ios/sdk/WeexSDK/Sources/WeexSDK.h               |  1 +
 7 files changed, 84 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bf61e99c/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj 
b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index ecf9fa6..e698847 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -590,6 +590,10 @@
                DCF0CD9E1EAF3A6B0062CA8F /* native-bundle-main.js in Resources 
*/ = {isa = PBXBuildFile; fileRef = DCF0CD9D1EAF3A6B0062CA8F /* 
native-bundle-main.js */; };
                DCF343671E49CAEE00A2FB34 /* WXJSExceptionInfo.h in Headers */ = 
{isa = PBXBuildFile; fileRef = DCF343651E49CAEE00A2FB34 /* WXJSExceptionInfo.h 
*/; settings = {ATTRIBUTES = (Public, ); }; };
                DCF343681E49CAEE00A2FB34 /* WXJSExceptionInfo.m in Sources */ = 
{isa = PBXBuildFile; fileRef = DCF343661E49CAEE00A2FB34 /* WXJSExceptionInfo.m 
*/; };
+               ED053500207F4DEB007B4568 /* JSContext+Weex.h in Headers */ = 
{isa = PBXBuildFile; fileRef = ED0534FE207F4DEB007B4568 /* JSContext+Weex.h */; 
settings = {ATTRIBUTES = (Public, ); }; };
+               ED053501207F4DEB007B4568 /* JSContext+Weex.h in Headers */ = 
{isa = PBXBuildFile; fileRef = ED0534FE207F4DEB007B4568 /* JSContext+Weex.h */; 
settings = {ATTRIBUTES = (Public, ); }; };
+               ED053502207F4DEB007B4568 /* JSContext+Weex.m in Sources */ = 
{isa = PBXBuildFile; fileRef = ED0534FF207F4DEB007B4568 /* JSContext+Weex.m */; 
};
+               ED053503207F4DEB007B4568 /* JSContext+Weex.m in Sources */ = 
{isa = PBXBuildFile; fileRef = ED0534FF207F4DEB007B4568 /* JSContext+Weex.m */; 
};
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -935,6 +939,8 @@
                DCF0CD9D1EAF3A6B0062CA8F /* native-bundle-main.js */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.javascript; name = 
"native-bundle-main.js"; path = "../../../../pre-build/native-bundle-main.js"; 
sourceTree = "<group>"; };
                DCF343651E49CAEE00A2FB34 /* WXJSExceptionInfo.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = 
WXJSExceptionInfo.h; sourceTree = "<group>"; };
                DCF343661E49CAEE00A2FB34 /* WXJSExceptionInfo.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path 
= WXJSExceptionInfo.m; sourceTree = "<group>"; };
+               ED0534FE207F4DEB007B4568 /* JSContext+Weex.h */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.h; path = 
"JSContext+Weex.h"; sourceTree = "<group>"; };
+               ED0534FF207F4DEB007B4568 /* JSContext+Weex.m */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = 
"JSContext+Weex.m"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -1299,6 +1305,8 @@
                                74AD99831D5B0E59008F0336 /* WXPolyfillSet.m */,
                                74862F771E02B88D00B7A041 /* JSValue+Weex.h */,
                                74862F781E02B88D00B7A041 /* JSValue+Weex.m */,
+                               ED0534FE207F4DEB007B4568 /* JSContext+Weex.h */,
+                               ED0534FF207F4DEB007B4568 /* JSContext+Weex.m */,
                        );
                        path = Bridge;
                        sourceTree = "<group>";
@@ -1722,6 +1730,7 @@
                                59D3CA4A1CFC3CE1008835DC /* NSTimer+Weex.h in 
Headers */,
                                C4424E5B1F24DA3D009F52E2 /* 
WXExtendCallNativeProtocol.h in Headers */,
                                74CFDD391F45939C007A1A66 /* 
WXRecycleListComponent.h in Headers */,
+                               ED053500207F4DEB007B4568 /* JSContext+Weex.h in 
Headers */,
                                D334510C1D3E19B80083598A /* WXCanvasModule.h in 
Headers */,
                                742AD73A1DF98C8B007DC46C /* WXResourceLoader.h 
in Headers */,
                                746319291C71B92600EFEBD4 /* WXModalUIModule.h 
in Headers */,
@@ -1761,6 +1770,7 @@
                                DCA445AC1EFA574A00D0CFA8 /* WXNetworkProtocol.h 
in Headers */,
                                DCA445C31EFA57DC00D0CFA8 /* 
WXAppMonitorProtocol.h in Headers */,
                                DCA445AF1EFA575D00D0CFA8 /* WXModuleProtocol.h 
in Headers */,
+                               ED053501207F4DEB007B4568 /* JSContext+Weex.h in 
Headers */,
                                DCA445B31EFA577300D0CFA8 /* WXLayoutDefine.h in 
Headers */,
                                DCA4459F1EFA56EC00D0CFA8 /* 
WXURLRewriteProtocol.h in Headers */,
                                DCA445A21EFA570100D0CFA8 /* 
WXScrollerComponent.h in Headers */,
@@ -2132,6 +2142,7 @@
                                74CFDD421F45941E007A1A66 /* 
WXRecycleListTemplateManager.m in Sources */,
                                747DF6831E31AEE4005C53A8 /* WXLength.m in 
Sources */,
                                77E65A0E1C155E99008B8775 /* WXDivComponent.m in 
Sources */,
+                               ED053502207F4DEB007B4568 /* JSContext+Weex.m in 
Sources */,
                                2A60CE9D1C91733E00857B9F /* WXSwitchComponent.m 
in Sources */,
                                744D61111E49979000B624B3 /* WXFooterComponent.m 
in Sources */,
                                745B2D6F1E5A8E1E0092D38A /* 
WXRecyclerUpdateController.m in Sources */,
@@ -2344,6 +2355,7 @@
                                DCA445791EFA55B300D0CFA8 /* 
WXThreadSafeCounter.m in Sources */,
                                DCA4457A1EFA55B300D0CFA8 /* 
WXSimulatorShortcutManager.m in Sources */,
                                DCA4457B1EFA55B300D0CFA8 /* WXAssert.m in 
Sources */,
+                               ED053503207F4DEB007B4568 /* JSContext+Weex.m in 
Sources */,
                                DCA4457C1EFA55B300D0CFA8 /* 
WXAppConfiguration.m in Sources */,
                                DCA4457D1EFA55B300D0CFA8 /* 
WXThreadSafeMutableDictionary.m in Sources */,
                                DCA4457E1EFA55B300D0CFA8 /* 
WXThreadSafeMutableArray.m in Sources */,

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bf61e99c/ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.h 
b/ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.h
new file mode 100644
index 0000000..3d1c378
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.h
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import <JavaScriptCore/JavaScriptCore.h>
+
+@interface JSContext (Weex)
+
+@property (nonatomic, strong) NSString *instanceId;
+
+@end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bf61e99c/ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.m 
b/ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.m
new file mode 100644
index 0000000..12e869e
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Bridge/JSContext+Weex.m
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import "JSContext+Weex.h"
+#import <objc/runtime.h>
+
+static NSString *wx_instanceIdKey;
+
+@implementation JSContext (Weex)
+
+- (NSString *)instanceId {
+    return (NSString *)objc_getAssociatedObject(self, &wx_instanceIdKey);
+}
+
+- (void)setInstanceId:(NSString *)instanceId {
+    objc_setAssociatedObject(self, &wx_instanceIdKey, instanceId, 
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bf61e99c/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m 
b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
index 6df02b9..342c6c0 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m
@@ -36,6 +36,7 @@
 #import "WXMonitor.h"
 #import "WXPolyfillSet.h"
 #import "WXAppMonitorProtocol.h"
+#import "JSContext+Weex.h"
 
 #import <dlfcn.h>
 
@@ -125,6 +126,7 @@
 
 - (void)setWeexInstanceId:(NSString *)weexInstanceId
 {
+    _jsContext.instanceId = weexInstanceId;
     _weexInstanceId = weexInstanceId;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bf61e99c/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m 
b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 5c4063e..19b9da8 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -154,10 +154,12 @@ typedef enum : NSUInteger {
         JSGlobalContextRelease(sandboxGlobalContextRef);
         [WXBridgeContext mountContextEnvironment:instanceContext];
         [_instanceJavaScriptContext setJSContext:instanceContext];
-    }
-    
-    if([_instanceJavaScriptContext 
respondsToSelector:@selector(setWeexInstanceId:)]) {
-        [_instanceJavaScriptContext setWeexInstanceId:_instanceId];
+        
+        if([_instanceJavaScriptContext 
respondsToSelector:@selector(setWeexInstanceId:)]) {
+            [_instanceJavaScriptContext setWeexInstanceId:_instanceId];
+        }
+        
+        [[NSNotificationCenter defaultCenter] 
postNotificationName:WX_INSTANCE_JSCONTEXT_CREATE_NOTIFICATION 
object:instanceContext];
     }
     
     return _instanceJavaScriptContext;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bf61e99c/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h 
b/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h
index cf6c080..56043f4 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXDefine.h
@@ -99,6 +99,8 @@ parts = [parts subarrayWithRange:(NSRange){0, parts.count - 
1}];\
 #define WX_MODULE_EVENT_FIRE_NOTIFICATION  @"WX_MODULE_EVENT_FIRE_NOTIFICATION"
 #define WX_ICONFONT_DOWNLOAD_NOTIFICATION  
@"WX_ICONFONT_DOWNLOAD_FINISH_NOTIFICATION"
 
+#define WX_INSTANCE_JSCONTEXT_CREATE_NOTIFICATION 
@"WX_INSTANCE_JSCONTEXT_CREATE_NOTIFICATION"
+
 /**
  *  @abstract export public method
  */

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bf61e99c/ios/sdk/WeexSDK/Sources/WeexSDK.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/WeexSDK.h 
b/ios/sdk/WeexSDK/Sources/WeexSDK.h
index a544ea1..3ed4385 100644
--- a/ios/sdk/WeexSDK/Sources/WeexSDK.h
+++ b/ios/sdk/WeexSDK/Sources/WeexSDK.h
@@ -71,5 +71,6 @@
 #import "WXAComponent.h"
 #import "NSObject+WXSwizzle.h"
 #import "Layout.h"
+#import "JSContext+Weex.h"
 
 #endif /* __OBJC__ */

Reply via email to