Loading

Wednesday, February 2, 2011

Create Third Party Ads Through WebView

First we create a view controller named MyAds

in MyAds.h


@interface MyAds : UIViewController
{
IBOutlet UIWebView *Web_Ad;
NSString *formatStr;

UINavigationController *ng;
id parentController;

IBOutlet UIView *viewAdDesc;
IBOutlet UIWebView *Web_Ad_Detail;

}
-(void)initWithStr:(NSString*)str;
-(IBAction)btnCancel_Clicked:(id)sender;
@property(nonatomic, retain) id ParentController;
@property (nonatomic, retain) IBOutlet UINavigationController *ng;
@end


in MyAds.m


#import "MyAds.h"

@implementation MyAds
@synthesize ParentController = parentController;
@synthesize ng;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[Web_Ad setBackgroundColor:[UIColor clearColor]];
[Web_Ad setOpaque:NO];
[Web_Ad loadHTMLString:formatStr baseURL:[NSURL URLWithString:@"http://www.ashiphone.blogspot.com/"]];
}
-(void)initWithStr:(NSString*)str
{
formatStr=str;
[formatStr retain];
}

#pragma mark WebviewDelegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"Page Start Loading");
if(webView==Web_Ad_Detail)
return YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSURL *urlReq=[request URL];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if([urlReq isEqual:[NSURL URLWithString:@"http://www.ashiphone.blogspot.com/"]])
NSLog(@"YES");
else if(urlReq)
{
[Web_Ad stopLoading];
[Web_Ad loadHTMLString:formatStr baseURL:[NSURL URLWithString:@"http://www.ashiphone.blogspot.com/"]];
[parentController addSubview:viewAdDesc];
ng.navigationBarHidden = YES;
[Web_Ad_Detail loadRequest:request];
}
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{


}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{

}

-(IBAction)btnCancel_Clicked:(id)sender
{
[viewAdDesc removeFromSuperview];
ng.navigationBarHidden = NO;
}




- (void)viewDidUnload {
[super viewDidUnload];
}


- (void)dealloc {
[super dealloc];
}


@end




Now We Have To Include This View As SubView Where We Wants the Ads

MyAds* childObject = [[MyAds alloc]initWithNibName:@"MyAds" bundle:[NSBundle mainBundle]];
childObject.ParentController=self.view;
childObject.ng = self.navigationController;
[childObject initWithStr:formatStr];
// formatStr is NSString with HTML code

No comments:

Post a Comment