Last active
August 18, 2016 07:40
-
-
Save andiradulescu/f156d6c7e022d7025643caa5d2133d28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; | |
self.webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | |
self.webView.delegate = self; | |
[self.view addSubview:self.webView]; | |
[self loadDisqusComments]; | |
} | |
- (void)loadDisqusComments | |
{ | |
// disqusURL should point to a hosted page on your site that uses this template: | |
// https://github.com/disqus/DISQUS-API-Recipes/blob/master/mobile/js/mobiletemplate.html | |
// or the universal code: https://disqus.com/admin/universalcode/ | |
// explained in detail here: https://help.disqus.com/customer/portal/articles/472098 | |
NSURL *disqusURL = [NSURL URLWithString:@"The URL to the hosted comments page"]; | |
NSURLRequest *request = [NSURLRequest requestWithURL:disqusURL]; | |
[self.webView loadRequest:request]; | |
} | |
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType | |
{ | |
// The following code opens all new windows in the current window | |
// Useful for "Forgot Password", "Basic Rules", "Terms of Service", and "Privacy Policy" | |
// which open in a new window by default | |
if (navigationType == UIWebViewNavigationTypeLinkClicked) { | |
[self.webView loadRequest:request]; | |
return NO; | |
} | |
NSString *urlString = [request.URL absoluteString]; | |
if ([urlString hasSuffix:@"#!auth%3Asuccess"] || [urlString hasSuffix:@"#!auth%3Acancel"]) { | |
[self loadDisqusComments]; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment