Last active
October 19, 2015 13:34
-
-
Save oded-regev/65e43e35c075d17fdfa8 to your computer and use it in GitHub Desktop.
iOS - Adding Advertiser ID param to all url in webview
This file contains hidden or 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
#pragma mark - WebView | |
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType | |
{ | |
NSString *url = request.URL.absoluteString; | |
NSString *advertiserId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; | |
NSString *adIdParam = [NSString stringWithFormat:@"api_user_id=%@",advertiserId]; | |
NSRange extraParam = [url rangeOfString:adIdParam]; | |
if (extraParam.location == NSNotFound) { | |
if ([url rangeOfString:@"?"].location == NSNotFound) { | |
url = [url stringByAppendingString:@"?"]; | |
} | |
else { | |
url = [url stringByAppendingString:@"&"]; | |
} | |
url = [url stringByAppendingString:adIdParam]; | |
NSURLRequest *newRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]]; | |
[webView loadRequest:newRequest]; | |
return NO; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment