Reputation:
So I can't find any documentation on how to do this, maybe someone knows what's going on here.
I'm in a UITableView (with a UINavigationController) in my application, and launching a UIWebView that loads an mp3 file on the internet by pushing the Web View's controller onto the navigation controller's stack. This works great, the file launches and plays in the quicktime player that Safari uses.
The problem is that once the audio file is finished playing, or the user clicks the done button, the player is released and the app goes back to an empty webView with my navigation bar. I can hit the back button to get back to my original UITableView, but that blank screen is ugly and needs to go.
So, what action can i use to put a [webviewcontroller.navigationcontroller popviewcontroller] message in? Is it loading an instance of some other class (like AVAudioPlayer) to play the audio? Do i need to subclass something? Apple's documentation on how it plays audio in UIWebView is basically nonexistant.
Upvotes: 5
Views: 2145
Reputation: 11
This might save someone an hour or two: the UIWebView behaves differently on the device and on the simulator (circa iOS 4.1).
I just spent some time trying to dismiss the webview on the simulator but it was working on the device the whole time.
Upvotes: 1
Reputation:
Ok, so I found a much better, much simpler solution; one that i had to delete lines of code from my app to use. I just used UIWebview initWithFrame:CGRectMake(0.0,0.0,1.0,1.0), didn't add it to the view, then called an NSURLRequest, and hooked it up to my button. The media player fullscreens automagically, and there's no need to call the nav controller.
Upvotes: 5
Reputation: 22767
You can fake it by having some javascript change location.href, and then doing something like this:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString* path=[[request URL] relativePath];
BOOL shouldContinue=YES;
if ([path isEqualToString:@"/_my_custom_link"])
{
shouldContinue=NO;
// do magical stuff
}
return shouldContinue;
}
If that doesn't work, you can always poll it by doing a
stringByEvaluatingJavaScriptFromString
Upvotes: 1