Skip to content

Commit

Permalink
Merge pull request #1299 from OneSignal/user_model/web_view_inspectab…
Browse files Browse the repository at this point in the history
…ility

[User model] Web view inspectability
  • Loading branch information
emawby authored Aug 10, 2023
2 parents 4984928 + 20e70ba commit fa82ce5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) {
@interface OneSignalLog : NSObject<OSDebug>
+ (Class<OSDebug>)Debug;
+ (void)onesignalLog:(ONE_S_LOG_LEVEL)logLevel message:(NSString* _Nonnull)message;
+ (ONE_S_LOG_LEVEL)getLogLevel;
@end
4 changes: 4 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ + (void)onesignalLog:(ONE_S_LOG_LEVEL)logLevel message:(NSString* _Nonnull)messa
onesignal_Log(logLevel, message);
}

+ (ONE_S_LOG_LEVEL)getLogLevel {
return _nsLogLevel;
}

void onesignal_Log(ONE_S_LOG_LEVEL logLevel, NSString* message) {
NSString* levelString;
switch (logLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ - (void)setupWebviewWithMessageHandler:(id<WKScriptMessageHandler>)handler {
self.webView = [[WKWebView alloc] initWithFrame:mainBounds configuration:configuration];
self.webView.backgroundColor = [UIColor clearColor];
self.webView.opaque = NO;
// https://webkit.org/blog/13936/enabling-the-inspection-of-web-content-in-apps/
if (@available(macOS 13.3, iOS 16.4, *)) {
if ([OneSignalLog getLogLevel] >= ONE_S_LL_DEBUG) {
if ([self.webView respondsToSelector:@selector(setInspectable:)]) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self.webView methodSignatureForSelector:@selector(setInspectable:)]];
BOOL value = YES; // Boolean parameters must be captured as a variable before being set as an argument
[invocation setTarget:self.webView];
[invocation setSelector:@selector(setInspectable:)];
[invocation setArgument:&value atIndex:2];
[invocation invoke];
}
}
}
[self addSubview:self.webView];

[self layoutIfNeeded];
Expand Down
13 changes: 13 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OneSignalWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ - (void)viewDidLoad {

_webView = [WKWebView new];
_webView.navigationDelegate = self;
// https://webkit.org/blog/13936/enabling-the-inspection-of-web-content-in-apps/
if (@available(macOS 13.3, iOS 16.4, *)) {
if ([OneSignalLog getLogLevel] >= ONE_S_LL_DEBUG) {
if ([_webView respondsToSelector:@selector(setInspectable:)]) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[_webView methodSignatureForSelector:@selector(setInspectable:)]];
BOOL value = YES; // Boolean parameters must be captured as a variable before being set as an argument
[invocation setTarget:_webView];
[invocation setSelector:@selector(setInspectable:)];
[invocation setArgument:&value atIndex:2];
[invocation invoke];
}
}
}
[self.view addSubview:_webView];

[self pinSubviewToMarginsWithSubview:_webView withSuperview:self.view];
Expand Down

0 comments on commit fa82ce5

Please sign in to comment.