|
4 | 4 | // Created by 曹犟 on 15/7/1. |
5 | 5 | // Copyright (c) 2015年 SensorsData. All rights reserved. |
6 | 6 |
|
7 | | -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_1 |
8 | | -#define supportsWKWebKit |
9 | | -#endif |
10 | | - |
11 | 7 | #import <objc/runtime.h> |
12 | 8 | #include <sys/sysctl.h> |
13 | 9 |
|
|
31 | 27 | #import "SensorsAnalyticsSDK.h" |
32 | 28 | #import "JSONUtil.h" |
33 | 29 |
|
34 | | -#if defined(supportsWKWebKit) |
35 | | -#import <WebKit/WebKit.h> |
36 | | -#endif |
37 | | - |
38 | | -#define VERSION @"1.6.36" |
| 30 | +#define VERSION @"1.6.37" |
39 | 31 |
|
40 | 32 | #define PROPERTY_LENGTH_LIMITATION 8191 |
41 | 33 |
|
@@ -122,6 +114,7 @@ @implementation SensorsAnalyticsSDK { |
122 | 114 | BOOL _showDebugAlertView; |
123 | 115 | NSString *_referrerScreenUrl; |
124 | 116 | NSDictionary *_lastScreenTrackProperties; |
| 117 | + BOOL _applicationWillResignActive; |
125 | 118 | } |
126 | 119 |
|
127 | 120 | static SensorsAnalyticsSDK *sharedInstance = nil; |
@@ -242,6 +235,7 @@ - (instancetype)initWithServerURL:(NSString *)serverURL |
242 | 235 | _showDebugAlertView = YES; |
243 | 236 | _referrerScreenUrl = nil; |
244 | 237 | _lastScreenTrackProperties = nil; |
| 238 | + _applicationWillResignActive = NO; |
245 | 239 |
|
246 | 240 | _filterControllers = [[NSMutableArray alloc] init]; |
247 | 241 | _dateFormatter = [[NSDateFormatter alloc] init]; |
@@ -429,27 +423,32 @@ - (BOOL)showUpWebView:(id)webView WithRequest:(NSURLRequest *)request andPropert |
429 | 423 |
|
430 | 424 | NSString *scheme = @"sensorsanalytics://getAppInfo"; |
431 | 425 | NSString *js = [NSString stringWithFormat:@"sensorsdata_app_js_bridge_call_js('%@')", jsonString]; |
| 426 | + |
| 427 | + //判断系统是否支持WKWebView |
| 428 | + Class wkWebViewClass = NSClassFromString(@"WKWebView"); |
| 429 | + |
432 | 430 | if ([webView isKindOfClass:[UIWebView class]] == YES) {//UIWebView |
433 | 431 | SADebug(@"showUpWebView: UIWebView"); |
434 | 432 | if ([request.URL.absoluteString rangeOfString:scheme].location != NSNotFound) { |
435 | 433 | [webView stringByEvaluatingJavaScriptFromString:js]; |
436 | 434 | return YES; |
437 | 435 | } |
438 | 436 | return NO; |
439 | | - } |
440 | | -#if defined(supportsWKWebKit ) |
441 | | - else if([webView isKindOfClass:[WKWebView class]] == YES) {//WKWebView |
| 437 | + } else if(wkWebViewClass && [webView isKindOfClass:wkWebViewClass] == YES) {//WKWebView |
442 | 438 | SADebug(@"showUpWebView: WKWebView"); |
443 | 439 | if ([request.URL.absoluteString rangeOfString:scheme].location != NSNotFound) { |
444 | | - [webView evaluateJavaScript:js completionHandler:^(id _Nullable response, NSError * _Nullable error) { |
| 440 | + typedef void(^Myblock)(id,NSError *); |
| 441 | + Myblock myBlock = ^(id _Nullable response, NSError * _Nullable error){ |
445 | 442 | NSLog(@"response: %@ error: %@", response, error); |
446 | | - }]; |
| 443 | + }; |
| 444 | + SEL sharedManagerSelector = NSSelectorFromString(@"evaluateJavaScript:completionHandler:"); |
| 445 | + if (sharedManagerSelector) { |
| 446 | + ((void (*)(id, SEL, NSString *, Myblock))[webView methodForSelector:sharedManagerSelector])(webView, sharedManagerSelector, js, myBlock); |
| 447 | + } |
447 | 448 | return YES; |
448 | 449 | } |
449 | 450 | return NO; |
450 | | - } |
451 | | -#endif |
452 | | - else{ |
| 451 | + } else{ |
453 | 452 | SADebug(@"showUpWebView: not UIWebView or WKWebView"); |
454 | 453 | return NO; |
455 | 454 | } |
@@ -1692,6 +1691,12 @@ - (void)applicationWillEnterForeground:(NSNotification *)notification { |
1692 | 1691 | - (void)applicationDidBecomeActive:(NSNotification *)notification { |
1693 | 1692 | SADebug(@"%@ application did become active", self); |
1694 | 1693 |
|
| 1694 | + if (_applicationWillResignActive) { |
| 1695 | + _applicationWillResignActive = NO; |
| 1696 | + return; |
| 1697 | + } |
| 1698 | + _applicationWillResignActive = NO; |
| 1699 | + |
1695 | 1700 | // 是否首次启动 |
1696 | 1701 | BOOL isFirstStart = NO; |
1697 | 1702 | if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) { |
@@ -1736,12 +1741,13 @@ - (void)applicationDidBecomeActive:(NSNotification *)notification { |
1736 | 1741 |
|
1737 | 1742 | - (void)applicationWillResignActive:(NSNotification *)notification { |
1738 | 1743 | SADebug(@"%@ application will resign active", self); |
1739 | | - |
| 1744 | + _applicationWillResignActive = YES; |
1740 | 1745 | [self stopFlushTimer]; |
1741 | 1746 | } |
1742 | 1747 |
|
1743 | 1748 | - (void)applicationDidEnterBackground:(NSNotification *)notification { |
1744 | 1749 | SADebug(@"%@ application did enter background", self); |
| 1750 | + _applicationWillResignActive = NO; |
1745 | 1751 |
|
1746 | 1752 | // 遍历trackTimer |
1747 | 1753 | // eventAccumulatedDuration = eventAccumulatedDuration + timeStamp - eventBegin |
|
0 commit comments