I have an agreement with a company (read: one single company) who would like to place an ad in an application I am creating. Since this is only one company, I figure that iAd is not the solution for me. This does, however, raise two questions:
1) Is it possible to open a link in safari from a webpage loaded into a UIWebView (I think via Javascript or similar techniques)?
2) Will Apple even accept an app with this kind of a开发者_StackOverflowds in it?
Thanks Kasper
Apple should have no issue with this type of ad. If you look at the UIWebView's delegate protocol, there is a way to override the behavior when you click a link, and you could then redirect the user to MobileSafari rather than processing the request in the UIWebView.
If you want the whole ad to be clickable, you could subclass UIWebView and override touch handlers on the (UI)View, or you could probably add a tap gesture recognizer.
-
This is the delegate method you'll want to implement, make it return NO and then take the URLRequest, get the URL and open the link with your UIApplication:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
I think that Apple will have no problem with this. In iOS apps you can even use ad providers other than iAd.
If you have a UIWebView
, you could possibly show the advertisement in that view, without launching Safari. Otherwise you can use
shouldStartLoadWithRequest:(NSURLRequest *)request
to intercept the click. This is a UIWebViewDelegate method that is called when a link is touched/clicked.
Here you can find a full example.
If you want to use static images to display the ad instead of HTML you can use JPAdvertisement. Its even made in the same sizes as iAd.
精彩评论