Reputation: 1740
App being built on Xcode 4, for a base IOS level of 4 and above, tested on a variety of IPhones. Info in app is loaded from a JSON feed.
In my attempts to track down what's happening I've repeatedly debugged through this app, a fairly basic one that has a few views, overall nothing amazing or new in it as far as apps go.
The problem manifests itself occasionally, a lot of the time in our testing it has been if we've turned off Wifi to test on a cellular connection the app will hang when loading.
What happens is that the splash screen appears and the white spinning activity wheel spins as if it's loading the ad (an ad is displayed as part of the overall loading process) but it just sits there spinning.
So, most obvious question, is the ad the problem? Is it large or loading slowly? No, the JSOn feed is speedy (we check every time the app hangs and inbetween times as well to make sure it's all loading ok) and the ad is about 20k.
Debugging gets as far as the didFinishLaunchingWithOptions method which I'll list below, it reaches the end of that method and the debugger essentially reports nothing else. It just sits there, nothing visible in the XCode debug navigator, no break points hit.
If step through that method, once it gets to the end it goes about 6-7 steps into compiled code then simply does the same thing.
Here's the code from that method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
[self loadData];
splashViewController = [[OurSplashViewController alloc] initWithNibName:nil bundle:nil];
splashViewController.delegate = self;
OurWebViewController *webViewController = (OurWebViewController *)[[[tabBarController viewControllers] objectAtIndex:2] topViewController];
webViewController.url = [NSURL URLWithString:@"http://m.testURL.com/this_app/"];
webViewController.path = @"/MyPath/Sample";
[window addSubview:splashViewController.view];
[window makeKeyAndVisible];
return YES;
}
So, it gets to the 'YES' of that method and then the debugger sails off into the land of ones and zeroes, reporting nothing back and hanging the app.
Has anyone got any idea what could be causing this?
UPDATE:
Seem to have isolated that the hanging comes down to a JSON call that is sent but no response is received. So my code should handle that after a while.
Here's the JSON code, maybe someone can notice something I'm missing in there:
- (void)fetchWithURL:(NSURL *)URL {
if (!URL) {
return;
}
self.jsonURL = URL;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:self.jsonURL];
if (timeout) {
[request setTimeoutInterval:timeout];
}
[request addValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
connection_ = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:YES];
[request release];
if (connection_ != nil) {
if ([self.delegate respondsToSelector:@selector(JSONFetchWillBeginDownload:)]) {
[self.delegate JSONFetchWillBeginDownload:self];
}
receivedData_ = [[NSMutableData alloc] initWithCapacity:0];
} else {
if ([self.delegate respondsToSelector:@selector(JSONFetch:downloadDidFailWithError:)]) {
[self.delegate JSONFetch:self downloadDidFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorUnknown userInfo:nil]];
}
}
}
According to Charles the reason for the failed response was:
Client closed connection before receiving entire response
I wonder is my timeout period too short?
Upvotes: 3
Views: 1735
Reputation: 1740
Looks like my timeout period was too short for the ads and as a result if the user was off WiFi then the JSON took a little too long to load, causing the issue.
Fixed it by upping the timeout to a normal level.
Upvotes: 0
Reputation: 27597
Use Charles Proxy for debugging the data exchange with your remote services and the ad-server.
See this tutorial for setting everything up.
Upvotes: 1
Reputation: 73936
If the spinning wheel (which is presumably part of the splash screen) is appearing, then the method you've posted is obviously working. If the splash screen is not disappearing, the obvious place to start debugging is in the code that sends the request and the code that receives the response then dismisses the splash screen.
Use a proxy like Charles to verify that the request is going out and a response is coming back. If that is the case, debug the code that receives the response and dismisses the splash screen. If that isn't the case, debug the code that sends the request.
If you don't get anywhere, I suggest posting the relevant code.
Upvotes: 1