提问人:user1244932 提问时间:9/30/2020 最后编辑:koenuser1244932 更新时间:3/6/2021 访问量:11799
WKWebView在后台,几个奇怪的断言
WKWebView in background, several strange assertion
问:
我想找出iOS中当前浏览器的userAgent。
因此,在Xcode创建的默认项目中,我添加了:
#import "ViewController.h"
#import <WebKit/WKWebView.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
dispatch_async(dispatch_get_main_queue(), ^{
WKWebView *obj = [[WKWebView alloc] initWithFrame:CGRectZero];
[obj evaluateJavaScript: @"navigator.userAgent" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
NSLog(@"evaluateJavaScript = %@ : %@", result, error);
NSLog(@"To make sure that webview alive: %@", obj);
}];
});
}
@end
它打印了我所期望的:
evaluateJavaScript = Mozilla/5.0 (iPad;CPU OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 : (null)
但在那之后,它会打印:
test4[1930:101220] 用法:<WKWebView:0x7f958f817800;帧 = (0 0; 0 0);layer = <CALayer:0x60000236ed00>>
test4[1930:101220] [断言] 获取断言时出错:<Error Domain=RBSAssertionErrorDomain Code=3“目标未运行或 缺少所需的目标权利” 用户信息={RBSAssertionAttribute=<RBSDomainAttribute| 域:“com.apple.webkit” 名称:“背景” sourceEnvironment:“(null)”>, NSLocalizedFailureReason=Target 不是 缺少正在运行或所需的目标授权}>
test4[1930:101220] [ProcessSuspension] 0x102dfed00 - ProcessAssertion: 无法获取 RBS 后台断言“WebProcess 后台” 具有 PID 1933 的进程的断言,错误:错误 Domain=RBSAssertionErrorDomain Code=3“目标未运行或 缺少所需的目标权利” 用户信息={RBSAssertionAttribute=<RBSDomainAttribute| 域:“com.apple.webkit” 名称:“背景” sourceEnvironment:“(null)”>, NSLocalizedFailureReason=Target 不是 缺少正在运行或所需的目标授权}
这看起来不太好。我的代码有问题吗, 是否有可能避免这些断言并仍然获得userAgent字符串?
答: 暂无答案
评论
"Target is not running or required target entitlement is missing"
"Target is not running or required target entitlement is missing"
webView
completionHandler
completionHandler
dispatch_async
webView