gpt4 book ai didi

ios - WKWebView在后台,几个奇怪的断言

转载 作者:行者123 更新时间:2023-12-03 11:15:44 25 4
gpt4 key购买 nike

我想在 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] usage: <WKWebView: 0x7f958f817800; frame = (0 0; 00); layer = <CALayer: 0x60000236ed00>>

test4[1930:101220] [assertion] Error acquiring assertion: <ErrorDomain=RBSAssertionErrorDomain Code=3 "Target is not running orrequired target entitlement is missing"UserInfo={RBSAssertionAttribute=<RBSDomainAttribute|domain:"com.apple.webkit" name:"Background"sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is notrunning or required target entitlement is missing}>

test4[1930:101220] [ProcessSuspension] 0x102dfed00 - ProcessAssertion:Failed to acquire RBS Background assertion 'WebProcess BackgroundAssertion' for process with PID 1933, error: ErrorDomain=RBSAssertionErrorDomain Code=3 "Target is not running orrequired target entitlement is missing"UserInfo={RBSAssertionAttribute=<RBSDomainAttribute|domain:"com.apple.webkit" name:"Background"sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is notrunning or required target entitlement is missing}


这看起来不太好。我的代码有问题吗,
是否可以避免这些断言并仍然获得 userAgent 字符串?

最佳答案

创建一个空的UIView并添加 WKWebView作为 subview 。

关于ios - WKWebView在后台,几个奇怪的断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64128421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com