IntroductioniVdopia's Rich ads can be served inside the applications without having the need to integrate native SDKs. This powerful feature is available by adding just a few lines of code inside the application.Please refer the following document to understand the meaning of different parameters that can be passed.SDK Free Integration Sample Code demonstrating the use of the adFetch API
(Adds a webview of size 320X75 to the top of the parent view ). UIWebView *webView = [[UIWebView alloc] initWithFrame : CGRectMake(0.0, 0.0, 320.0, 75.0)]; [webView setBackgroundColor:[UIColor clearColor]]; [webView setOpaque:NO]; webView.allowsInlineMediaPlayback = YES; webView.mediaPlaybackRequiresUserAction = NO; [self. view addSubView : webView]; UIWebView *webView = [[UIWebView alloc] initWithFrame : CGRectMake(0.0, self.view.frame.size.height - 75.0 , 320.0, 75.0)]; [webView setBackgroundColor:[UIColor clearColor]]; [webView setOpaque:NO]; webView.allowsInlineMediaPlayback = YES; webView.mediaPlaybackRequiresUserAction = NO; [self. view addSubView : webView]; UIWebView *webView = [[UIWebView alloc] initWithFrame : CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height); Sample Code demonstrating how to request a vdobanner of size 320 X 75 from the Vdopia Server.
NSString *useragent = @"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0"; // Get the User-Agent NSString *ipAddress = @"10.0.0.5"; // Get the device's IP address NSString *adFormat = @"vdobanner"; // The adFormat to be played NSString *APIkey = @"AX123"; // The unique API key // Setting the banner location as top, locbot=0. This will allow the banner to be served at the top // of the HTML page and expand to bottom. Setting locbot=1, will do the reverse. NSString *url = [NSString stringWithFormat:@"http://serve.vdopia.com/adserver/html5/adFetch/?output=xhtml&requester=random &adFormat=%@&ak=%@&version=1.0&ipAddress=%@&ua=%@&bannerSize=”320X75”&locbot=0”, adFormat,APIkey,ipAddress, useragent]; NSString *encodedURLString = [url stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];// Start a request to get the contents from the vdopia Server NSURLRequest* theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:encodedURLString] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0]; NSError * error=nil; NSURLResponse * response=nil; // Start an synchronous request NSData *data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error]; if (error != nil) { /* Some problem with the connection, take fallback action */ NSString *message = NSLocalizedString (@"Unable to initiate request.", @"NSURLConnection initialization method failed."); NSLog(@"%@ %@",message,url); // Or Add code here to play ads from another server } else { NSString* aStr; aStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSLog(@"data is %@", aStr); // If the data is received , allocate a parser to parse the XHTML contents. NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; parser.delegate = self; [parser parse]; }
- (void)parserDidStartDocument:(NSXMLParser *)parser { } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError; { } - (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError *)validationError; { } -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if([[attributeDict objectForKey:@"type"] isEqualToString : @"error" ]) { // No ads returned from Vdopia Server, you may want to call another ad server here } if([elementName isEqualToString:@"xhtml"]) { fetch = YES; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if(fetch) { fetch = NO; loadString = string; [webView loadHTMLString:loadString baseURL:[NSURL URLWithString:@"http://serve.vdopia.com/adserver/html5/"]]; [webView loadHTMLString:loadString baseURL:nil]; } } - (void)parserDidEndDocument:(NSXMLParser *)parser { } Requesting other ad formats from the Vdopia ServerIn order to fetch other adformats, just change the adFormat parameter in the request. |