Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

938 Fixed Device UA being empty on First Bid Request #957

Merged
20 changes: 4 additions & 16 deletions PrebidMobile/PrebidMobileRendering/Utilities/PBMUserAgentService.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ - (void)setUserAgent {

- (void)setUserAgentInThread:(id<PBMNSThreadProtocol>)thread {
if (!thread.isMainThread) {
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_sync(dispatch_get_main_queue(), ^{
[self setUserAgent];
});
return;
Expand All @@ -95,21 +95,9 @@ - (void)setUserAgentInThread:(id<PBMNSThreadProtocol>)thread {
}

- (void)generateUserAgent {
@weakify(self);
[self.webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
@strongify(self);
if (!self) { return; }

if (error) {
PBMLogError(@"%@", error);
}
else if (result) {
NSString *resultString = [NSString stringWithFormat:@"%@", result];
self.userAgent = (resultString) ? resultString : @"";
}

self.webView = nil;
}];
self.userAgent = [self.webView valueForKey:@"userAgent"];
jsligh marked this conversation as resolved.
Show resolved Hide resolved
self.userAgent = (self.userAgent) ? self.userAgent : @"";
self.webView = nil;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,21 @@ class PBMUserAgentServiceTest: XCTestCase {
expectationUserAgentExecuted = expectation(description: "expectationUserAgentExecuted")

let userAgentService = PBMUserAgentService.shared
let userAgentString = userAgentService.getFullUserAgent()

// Waiting for JS userAgent execute asynchronously
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
let userAgentString = userAgentService.getFullUserAgent()

//Should start with a useragent from the Web View
XCTAssert(userAgentString.PBMdoesMatch("^Mozilla"))

if UIDevice.current.userInterfaceIdiom == .pad {
XCTAssert(userAgentString.PBMdoesMatch("iPad"))
} else if UIDevice.current.userInterfaceIdiom == .phone {
XCTAssert(userAgentString.PBMdoesMatch("iPhone"))
}

XCTAssert(userAgentString.PBMdoesMatch("AppleWebKit"))

self.expectationUserAgentExecuted?.fulfill()
//Should start with a useragent from the Web View
XCTAssert(userAgentString.PBMdoesMatch("^Mozilla"))

if UIDevice.current.userInterfaceIdiom == .pad {
XCTAssert(userAgentString.PBMdoesMatch("iPad"))
} else if UIDevice.current.userInterfaceIdiom == .phone {
XCTAssert(userAgentString.PBMdoesMatch("iPhone"))
}

XCTAssert(userAgentString.PBMdoesMatch("AppleWebKit"))

self.expectationUserAgentExecuted?.fulfill()

waitForExpectations(timeout: 5)
}

Expand Down