Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

adriweb

macrumors newbie
Original poster
Oct 23, 2010
13
1
France
Hi,

I currently have a UIWebView at the bottom of my app that basically displays Google Adsense Ads.

What I would like to do is open Safari when a user clicks the ad in the webview.

I have already looked for that a lot, and the only thing I could find is a code like that :

Code:
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        [[UIApplication sharedApplication] openURL:request.URL];
        return false;
    }
    return true;
}

So, when I add this to my code, I change the name "webView" by the name of what my UIWebView is ("pubadsense"), so it finally looks like that :

Code:
[pubadsense loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://adriweb.free.fr/pub.html"]]];
	
	- (BOOL)pubadsense:(UIWebView *)pubadsense shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
		if (navigationType == UIWebViewNavigationTypeLinkClicked) {
			[[UIApplication sharedApplication] openURL:request.URL];
			return false;
		}
		return true;
	}


But when I want to compile, Xcode tells me :


/Users/adrien/Desktop/iSEN-Lite/Classes/ThirdViewController.m:23: warning: cast from pointer to integer of different size

/Users/adrien/Desktop/iSEN-Lite/Classes/ThirdViewController.m:23: error: expected ';' before ':' token


What am I supposed to do now ?

Isn't the code I found working for this particular case ?


Thanks !
 

adriweb

macrumors newbie
Original poster
Oct 23, 2010
13
1
France
Thanks, but when I leave "webView" like that :

Code:
	- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {


Xcode tells me "webView" is undeclared....


But the
error: expected ';' before ':' token
is still here .....
 

adriweb

macrumors newbie
Original poster
Oct 23, 2010
13
1
France
You're not trying to define your delegate method within another method, are you?

Hmm.... Maybe, I'm not sure...

EDIT : Yes I think I am ... so Where and how should I declare it correctly ?

(Yep, I'm probably a "noob" in iPhone developing, as I started few days ago...)

This is what I have :



Would giving the source help (I mean, in a .zip file)
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
... so Where and how should I declare it correctly ?
How: you should declare it like any other method in the class.
Where: doesn't really matter for delegate methods; wherever makes sense for you.

I think you are so fresh to iPhone developing that I'm gonna suggest you step back from the real coding and go learn the basics of iPhone Development / Objective-C programming. Don't come back to this issue until you are comfortable with them.
 

adriweb

macrumors newbie
Original poster
Oct 23, 2010
13
1
France
How: you should declare it like any other method in the class.
Where: doesn't really matter for delegate methods; wherever makes sense for you.
What's weird though is that I've seen several open-source projects that kind of did the same.... Well, I'll keep trying...

I think you are so fresh to iPhone developing that I'm gonna suggest you step back from the real coding and go learn the basics of iPhone Development / Objective-C programming. Don't come back to this issue until you are comfortable with them.
Oh well, yes, you're 100% right, I actually wanted to build a little app with some parts taken from examples here and there, so, I will definitely learn the basics first, but it shouldn't take so long (I hope) considering I also develop in some other languages... :)


Thanks for your help though !
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
What's weird though is that I've seen several open-source projects that kind of did the same....
"Kind of" doesn't count. Precision is important. I doubt those projects (don't be afraid to link to these kinds of things when discussing them) are violating the basic syntax of method implementation; if they are, that's bad cause they won't even compile, as you've run into.
 

adriweb

macrumors newbie
Original poster
Oct 23, 2010
13
1
France
While I'm still on that... do you have an example of what I'm trying to do ?



beginning-iphone-development-exploring-sdk-dave-mark-paperback-cover-art.jpg

And by the way, I bought this book, so I'll dive into the basics as soon as possible (I'm a student and I actually have a lot of school things to do ...)
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
While I'm still on that... do you have an example of what I'm trying to do ?
Not off the top of my head, no. You may need to use some creativity to mold existing solutions to fit your needs.

beginning-iphone-development-exploring-sdk-dave-mark-paperback-cover-art.jpg

And by the way, I bought this book, so I'll dive into the basics as soon as possible (I'm a student and I actually have a lot of school things to do ...)
Make sure you understand Objective-C before you begin that book.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.