How to deal with purgeIdleCellConnections on 3G network? - iphone

I added thirdparty SDK to my project, and I got purgeIdleCellConnections errors when using slow 3G network .
purgeIdleCellConnections: found one to purge conn = 0x1f55b300
There is no problem on wifi network , because it don't use the cellular network for the image downloads.
I have to determine if network type is wifi or 3G :
+ (BOOL) IsEnableWIFI {
return ([[Reachability reachabilityForLocalWiFi]
currentReachabilityStatus] != NotReachable);
}
+ (BOOL) IsEnable3G {
return ([[Reachability reachabilityForInternetConnection]
currentReachabilityStatus] != NotReachable);
}
But I think this is not a good idea. How to deal with it ?
Thank you for any replies.

I have observed this debug message coming out of the iOS 6.0 SDK (when on the device connected to cellular network), correlates to active AJAX calls being terminated in my app. However it is very difficult to prove anything since this only occurs when rendering the web page in a UIWebView. I am just saying I don't think the messages are benign. I think they might indicate a bug in the Apple framework that is overly aggressive in terminating connections. It is hard to get instrumentation on the javascript running inside the UIWebView that makes the AJAX calls, so it is all highly speculative at this time.

I believe this is a debug log which came in IOS6 SDK, don't worry about this.

Related

NSURLConnection Intermittent Failure iPhone Device On LAN

I am using NSURLConnection to communicate with a web service on my LAN. When using the Xcode Simulator everything works as expected. However, when using an iPhone the connection mostly times out (but not always).
The iPhone is connected to the LAN via wifi. I can consistently browse the web server (which is hosting the web service) using Safari.
However, the app mostly fails. It returns in the didFailWithError function reporting "The request timed out".
The app will intermittently succeed (behaving exactly as expected). I can see no pattern for success or failure. It may fail several times and then succeed and then fail again (without restarting the app). I estimate a 90%+ failure rate.
The web service always receives the request and always responds. It appears the failure happens with the device not receiving or handling the response.
I can see no obvious problem with my network. Certainly there is no IP address clash.
I am completely new to apps, Apple, Xcode and iPhone. So this could be something really very obvious to you. Any ideas what I could look at to resolve this?
The environment I'm currently using for development is as follows:
Mac OS X (10.7.4)
Xcode 4 (targetting 4.3)
iPhone 3GS (5.1.1)
Obviously I cannot give you the absolute answer, but can hopefully help you track the problem down.
First, you want vet your web service. Put a JPEG image in a public Dropbox folder. Now try to download that image with your code as well as view it with Safari. If Safari works but your code does not, then you know your code is the problem.
If both fail then the phone may have a bad transceiver, or your WIFI network may be flakey. Take the phone to some public WIFI location and redo the test. If both still fail on a second network, the phone is probably defective.
If in all cases Safari works but your code does not, then please post as much of your code as possible. Also, if using the asynchronous interface, are you getting redirected? Asked for credentials? Etc. I would be inclined to add every NSURLConnection delegate method and at least add a log so you know what's going on - that is log all responses. You can also get the html return code from the response:
assert([response isKindOfClass:[NSHTTPURLResponse class]]);
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
htmlStatus = [httpResponse statusCode];
if(htmlStatus != 200) NSLog(#"Server Response code %i", htmlStatus);

iPhone app loses internet connectivity (NSURLConnection not returning)

I'm having an issue that's incredibly hard to debug. If my app is using WiFi and it sits idle for around 30 minutes, sometimes when I wake it up, the NSURLConnection no longer responds. Requests are sent, but never return.
At first, I thought this was a memory bug with the instances being released too early and thus never returning a response. However, if I put the app in the background, go into settings, turn off WiFi so 3G is used exclusively, and return to the app, the internet connection magically comes back to life and all pending NSURLConnections return and complete.
Obviously this is an issue for people using WiFi. Is this really a WiFi issue, or am I missing something? Going to another app like Safari, using the WiFi radio and returning to my app doesn't solve the problem - connections still don't return. I've traced this with Xcode and I'm running out of ideas.
Also 'Application Uses WiFi' Info.plist flag is set to ON and this is firmware 5.1.
is 'Application Uses WiFi' the same as UIRequiresPersistentWiFi?
Update: This has nothing to do with the Wifi flag - it can die within 5 minutes. So far, I've only been able to duplicate it on my iPhone 4s with 5.1 firmware. It's not really a solution, but I'm erasing the phone to try it with a fresh install to see if that has any effect. I have verified that NSURLConnection is always called on the main thread, and set breakpoints at connection:failedWithError: and connection:didReceiveResponse:. When the connection dies, none of these return until I disable and re-enable WiFi, and then all return at once. This happens on a local server as well, and the server still returns if I ping it with a web browser.
For any others running into this issue, it's due to TestFlight v1.0 and below:
Why does NSURLConnection fail to reach the backend?
Are you actually transmitting/receiving any data through the NSURLConnection? If not, is it possible you are hitting a TCP session timeout? Seems unlikely if the problem persists on a local server, but any intervening stateful firewall/packet inspector might be casting off your TCP connection.

about WifiManager.bundle

What will be the result of the
libHandle = dlopen("/System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager", RTLD_LAZY);
I'm using this for getting wifi info on ipod os 3.1.2., because when I NSLog(#"Result %#",libhandle); I'm getting null what should be the answer,
thanks
According to this discussion, doing the above will return NULL on the iPhone Simulator, because it lacks the required bundle. If you are still running into issues with this on the device, it might be that Apple has changed the internal file structure for that system item. This is one of the reasons why it is bad to rely in private APIs.
For more on WiFi snooping, you might refer to the source code for this project, because they might have resolved these issues. However, once again I'd like to remind you that you will not be able to submit an application to the App Store that uses this, because of the private API calls. Apple is now scanning all submitted applications for these calls and instantly rejecting them.

iPhone - app crashing with poor internet connection

I have an iPhone app which communicates with a server to get the data being displayed. I have tested this app on a wifi connection and a good 3G connection. The app works without an issue. But if I test the app on a poor connection, the app crashes.
I get an XML from the server and parse it before displaying the data. I have put in the NSXMLParser method to show an alert if the parsing fails. The n/w connection code is also placed in try/catch blocks and we show an alert if the control goes to the catch block.
On a poor internet connection, the app just crashes (doesn't even go to the catch block) and checking the crash logs suggests the app could not get the complete response. Shouldn't it go to the catch block in that case? (I am using a wrapper class to make a synchronous connection)
This will always be an issue in any app using the internet if the connection is poor. Is there any way we can avoid this?
Thanks.
I am using the code provided here as the base for creating connections and getting the response
This isn't a direct answer, but may I suggest the ASIHTTPRequest library? I searched around for a long time looking for a good networking library and this seemed to be pretty bullet-proof through all sorts of connection issues.
It took me an afternoon to remove the lousy library I wrote and to integrate it. The other nice thing about it is that it can be done asynchronously.
It is available here: http://allseeing-i.com/ASIHTTPRequest/

Determining when an EDGE connection comes back after a dropout on an iPhone

I've incorporated Apple's Reachability sample into my own project so I know whether or not I have a network connection - if I don't have a network connection, I don't bother sending out and requests. I decided to go with the status notification implementation because it seemed easier to have the reachablity updated in the background and have the current results available immediately as opposed to kicking off a synchronous request whenever I want to make a network connection.
My problem is that I start getting false negatives when on an EDGE network - the phone has connectivity, but the app thinks this isn't the case. My understanding is you don't get a notification when an EDGE connection, so my assumption is that I lost and regained the connection at some point. Restarting the app is usually sufficient to see the network connection.
This isn't an optimal solution, so I was wondering if anybody else came across this problem and had any thoughts on a solutions.
(I don't know whether this applies to 3G as well; I'm running a first gen iPhone).
Reachability notificataions didn't seem to be reliable for me either, for detecting Wi-Fi. So I just use polling instead. Checking every 5 seconds seems to do no harm.
- (void) checkReachability {
BOOL connected = ([[Reachability sharedReachability] localWiFiConnectionStatus] == ReachableViaWiFiNetwork);
// Do something...
[self performSelector:#selector(checkReachability) withObject:nil afterDelay:5.0];
}
There is a nice reachability example on the net. it works wonderfully well:
http://servin.com/iphone/iPhone-Network-Status.html
But you see, when I try to use it my own way, it just bombs.
Tried to implement it using:
NSString *sCellNetwork;
NSString *sNetworkReachable;
if (flags & kSCNetworkFlagsReachable || flags & kSCNetworkReachabilityFlagsIsWWAN)
{do it}
else {
Network fail alert;
}