I'm working on a simple UIWebView app for myself and a few friends. It's just a wrapper of the mobile site for Google Music. By including it in a UIWebView app, it fixes the missing background audio feature that stopped working in iOS 5. I've got it checking if there's an internet connection but, it only does that when the app is first launched (or quit and relaunched). Is there a way for Reachability to keep checking for an internet connection and show an error message every time the app is opened? I was also wondering if there was any way to reload the UIWebView when the device has been connected to the internet again? Here's my ViewController.m file.
Here's the source code for the entire app:
http://dl.dropbox.com/u/17689746/playmusic.zip
I've tried about 10 different ideas and none seem to really work the way that I'd like it to. Any help would be greatly appreciated. Thanks!
Code:
//
// ViewController.m
// playmusic
//
// Created by celebi23 on 4/16/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"
#import "Reachability.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL = @"https://music.google.com"; NSURL *url = [NSURL URLWithString:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj];
// Do any additional setup after loading the view, typically from a nib.
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"Play Music requires an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[myAlert show];
[myAlert release];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
Here's the source code for the entire app:
http://dl.dropbox.com/u/17689746/playmusic.zip
I've tried about 10 different ideas and none seem to really work the way that I'd like it to. Any help would be greatly appreciated. Thanks!