Skip to content

Commit de1615f

Browse files
committed
use WKWebView instead of deprecated UIWebView
1 parent 6538fe2 commit de1615f

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ typedef NS_ENUM(NSUInteger, OSNotificationDisplayType) {
133133
@property(readonly)NSString* subtitle;
134134
@property(readonly)NSString* body;
135135

136-
/* Web address to launch within the app via a UIWebView */
136+
/* Web address to launch within the app via a WKWebView */
137137
@property(readonly)NSString* launchURL;
138138

139139
/* Additional key value properties set within the payload */

iOS_SDK/OneSignalSDK/Source/OneSignalWebView.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
*/
2727

2828
#import <UIKit/UIKit.h>
29+
#import <WebKit/WebKit.h>
2930

30-
@interface OneSignalWebView : UIViewController <UIWebViewDelegate>
31+
@interface OneSignalWebView : UIViewController <WKNavigationDelegate>
3132

3233
@property(nonatomic, copy)NSURL *url;
33-
@property(nonatomic)UIWebView *webView;
34+
@property(nonatomic)WKWebView *webView;
3435
@property(nonatomic)UIActivityIndicatorView *uiBusy;
3536

3637
-(void)dismiss:(id)sender;

iOS_SDK/OneSignalSDK/Source/OneSignalWebView.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ @implementation OneSignalWebView
4242
-(void)viewDidLoad {
4343
[super viewDidLoad];
4444

45-
_webView = [UIWebView new];
46-
_webView.delegate = self;
45+
_webView = [WKWebView new];
46+
_webView.navigationDelegate = self;
4747
[self.view addSubview:_webView];
4848

4949
[self pinSubviewToMarginsWithSubview:_webView withSuperview:self.view];
@@ -73,17 +73,19 @@ -(void)dismiss:(id)sender {
7373
}];
7474
}
7575

76-
-(void)webViewDidStartLoad:(UIWebView *)webView {
76+
-(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
7777
[_uiBusy startAnimating];
7878
}
7979

80-
-(void)webViewDidFinishLoad:(UIWebView *)webView {
81-
self.title = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
82-
self.navigationController.title = self.title;
83-
[_uiBusy stopAnimating];
80+
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
81+
[_webView evaluateJavaScript:@"document.title" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
82+
self.title = result;
83+
self.navigationController.title = self.title;
84+
[_uiBusy stopAnimating];
85+
}];
8486
}
8587

86-
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
88+
-(void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
8789
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:error.localizedDescription];
8890
}
8991

0 commit comments

Comments
 (0)