From 6648d4401705aea4027cef01700867d414e59517 Mon Sep 17 00:00:00 2001 From: "qianyuan.wqy" Date: Wed, 18 Sep 2019 14:55:30 +0800 Subject: [PATCH] [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 9705761d5c..16e1aa6f71 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 8f4bf9e380..1a09028f73 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -60,6 +60,9 @@ NSTimeInterval JSLibInitTime = 0; +static NSString* lastPageInfoLock = @""; +static NSDictionary* lastPageInfo = nil; + typedef enum : NSUInteger { WXLoadTypeNormal, WXLoadTypeBack, @@ -316,6 +319,11 @@ - (void)renderWithURL:(NSURL *)url options:(NSDictionary *)options data:(id)data 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 @@ - (void)renderView:(id)source options:(NSDictionary *)options data:(id)data _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 @@ - (void)didDisappear } } ++ (NSDictionary*)lastPageInfo +{ + NSDictionary* result; + @synchronized (lastPageInfoLock) { + result = [lastPageInfo copy]; + } + return result; +} + @end @implementation WXSDKInstance (Deprecated)