You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by mo...@apache.org on 2019/09/18 06:55:43 UTC

[incubator-weex] 01/01: [iOS] Add last page info.

This is an automated email from the ASF dual-hosted git repository.

moshen pushed a commit to branch record-last-url
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git

commit 6648d4401705aea4027cef01700867d414e59517
Author: qianyuan.wqy <qi...@taobao.com>
AuthorDate: Wed Sep 18 14:55:30 2019 +0800

    [iOS] Add last page info.
---
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h |  6 ++++++
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
index 9705761..16e1aa6 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
@@ -440,6 +440,12 @@ typedef enum : NSUInteger {
  */
 - (void)setViewportWidth:(CGFloat)width;
 
+/**
+ * @abstract Get information about the last rendered page.
+ Useful fot debugging and fixing online bugs.
+ */
++ (NSDictionary*)lastPageInfo;
+
 /** 
  * Deprecated 
  */
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 8f4bf9e..1a09028 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -60,6 +60,9 @@ NSString *const bundleResponseUrlOptionKey = @"bundleResponseUrl";
 
 NSTimeInterval JSLibInitTime = 0;
 
+static NSString* lastPageInfoLock = @"";
+static NSDictionary* lastPageInfo = nil;
+
 typedef enum : NSUInteger {
     WXLoadTypeNormal,
     WXLoadTypeBack,
@@ -316,6 +319,11 @@ typedef enum : NSUInteger {
         return;
     }
     WXLogInfo(@"pageid: %@ renderWithURL: %@", _instanceId, url.absoluteString);
+    
+    @synchronized (lastPageInfoLock) {
+        lastPageInfo = @{@"pageId": [_instanceId copy], @"url": [url absoluteString] ?: @""};
+    }
+    
     [WXCoreBridge install];
     if (_useBackupJsThread) {
         [[WXSDKManager bridgeMgr] executeJSTaskQueue];
@@ -339,6 +347,10 @@ typedef enum : NSUInteger {
     _options = [options isKindOfClass:[NSDictionary class]] ? options : nil;
     _jsData = data;
     WXLogInfo(@"pageid: %@ renderView pageNmae: %@  options: %@", _instanceId, _pageName, options);
+    
+    @synchronized (lastPageInfoLock) {
+        lastPageInfo = @{@"pageId": [_instanceId copy], @"options": options ? [options description] : @""};
+    }
 
     [WXCoreBridge install];
     if (_useBackupJsThread) {
@@ -1141,6 +1153,15 @@ typedef enum : NSUInteger {
     }
 }
 
++ (NSDictionary*)lastPageInfo
+{
+    NSDictionary* result;
+    @synchronized (lastPageInfoLock) {
+        result = [lastPageInfo copy];
+    }
+    return result;
+}
+
 @end
 
 @implementation WXSDKInstance (Deprecated)