My iPhone app sends data persistently over the network, and can handle having the network completely unavailable for a time. However I do my dev on an ipod and have difficulty testing 3G connectivity issues; My question: is there period of non-connectivity, while an app is in the foreground, after which the iphone will stop checking for the network, such that there are no bars and reachability returns 0 until the user "wakes" the phone, e.g. by locking/unlocking? Or can e.g. 1 hr without data network pass and the iphone will recognize that the network is back and reachability will start returning true (I am polling every 1 minute while there is not connection to my server).
This is my experience with wifi: if, while running my app, the ipod hasn't connected to a wifi network for 1/2 hr, it stops looking for networks, and I need to lock and unlock it to stir the device into looking again.
One other thing: the iPhone has the screen dimmed by the proximity sensor while all this persistent network use is happening.
Wi-Fi going down after 30 min of inactivity is a documented behavior. Cellular network is always active, unless turned off by the user. So if it goes down for a while it should get back online automatically when possible even if there was no user activity.
Related
I want to track my iPhone 6s device for the probe requests it is sending to connect to the WiFi router.
This is my current setup:
I have kept the WiFi on and have forgotten the network, in the phone so that it probes new APs.
1.The location and services is disabled.
2.The Mobile-Data is also On.
3.I am using Aircrack-ng to trace the probe requests to the router.
4.I ran the setup to get the probe requests for 1 hour, but still couldn't get the entry for the iPhone.
5.I also used wireshark and a different router to detect the iPhone but still it is not available. The capture duration was 1 hour.
6.The phone screen was randomly on and off.
I have read that from iOS8 Apple uses MAC randomization for the user safety so that they can't be tracked, but now I have a clear insight of what are the conditions when the randomization occurs(location disabled and packet data disabled and phone in sleep mode.)
I want to know that is the randomization actually happening and even if it is happening, how do I know the new Locally Randomized address of my device to trace it on Aircrack-ng/Wireshark.
And If the randomization process is actually not happening then why can't I see my iPhone in the list.
Some articles I followed:
http://blog.mojonetworks.com/ios8-mac-randomization-analyzed/.
http://www.cisco.com/c/en/us/td/docs/wireless/controller/technotes/8-0/iPhone_roam/b_iPhone-roaming.html#concept_79EB523637BD49F3AE876F9C1C95DD69
I want to log the number of bytes being transferred from my iPhone app to server so that I could put a watch on the bandwidth being eaten up and could take necessary actions.
How can I do this?
In Instruments there is Network Activity Monitor that does what you need. You can always correlate your findings with network usage numbers in your Settings.app on actual device. Settings->General->Usage
Update:
Second approach:
Make sure you use cellular connection first
Reset your data counter.
Launch your app and perform operations that interested in
Quit your app and see the traffic used in Settings.app
On the picture below is traffic used for my app in 2 minutes.
I studied the iOS programming guide in the iOS SDK. In that in "Tuning for Performance and Responsive ss" section I am having problem. In the subsection named "Using Wi-Fi" under the above section there is one note which is like below:
Note: Note that even when UIRequiresPersistentWiFi has a value of true, it has no effect when the device is idle (that is, screen-locked). The application is considered inactive, and although it may function on some levels, it has no Wi-Fi connection.
According to my interpretation what this note says is that once the screen is locked of iPhone there is no Wi-Fi connection with iPhone. To check this what I did is, I implemented one simple application which sends one UDP packet every 6 minutes and then sleeps using usleep function of C. Now after starting this application I lock my iPhone with the button above iPhone, but still it can send the packet every 6 minute. If Wi-Fi connection really gets closed according to above note then how can it send the packet. I seen the packet in wireshark, it is having the ip address what Wi-Fi router provided to it. So I think documentation of iPhone SDK is wrong.
You didn't say if the iPhone is in its dock when you did the test. With the screen locked and the charging cable disconnected the iPhone will close the Wifi connection. When the charging cable is connected then the WIfi connection will remain open.
Lets consider that I am connected to internet through 3G in my App. When a wi-fi hot spot seems to be appearing, can I programmatically switch to the wi-fi. Is this vice-versa condition possible?
iOS does this automatically by itself!
If no known WiFi network is found, it uses cellular data. If it finds a known WiFi-network, it connects to and uses that network instead.
If any WiFi-network is found, and your application requests access to the internet, iOS (usually) automatically presents an alertView and lets the user log in to a WiFi-network. If the user does not log into a WiFi-network, it stays on the 3G-network. When iOS 7 comes, iOS may connect to Hotspot 2.0 networks automatically as well.
Apple keeps individual apps on a tight leash, and so they do not let apps control things like this.
I am developing a network application on iPhone that requires internet connection all the time. However, once I login to the server and keep the iPhone idle for a while, the iPhone goes to sleep mode and disconnects my network connection (it logs me out).
If I run the same application on iPhone, while the iPhone is connected to the PC through USB cable, it never loses its network connection.
In the info.plist file I have added these two flags, but does not seem to have any effect.
UIRequiresPersistentWifi -> true
SBUsesNetwork - integer ->3
Am I missing anything? Could you please let me know how can I make sure that the network connection is persistent throughout the life of the application?
In your application delegate ("appDelegate"), disable the idle timer in the +initialize method:
myApp.idleTimerDisabled = YES;
Note that this will keep your iPhone from sleeping while your app is open. This can present issues with battery life.
Another option might be to set up a background thread that opens a small CFStream on a timed basis.
What do you mean by "logs me out" here? At the network level, there is no "logged in" (*). There are only packets. You send them or you don't. So does your server process have some expectation of packets or messages arriving periodically? If it does, then you must send them, and that means that you can't go idle (idleTimerDisabled = YES). If you control the server, it is better to make it less demanding about how often you talk to it. This all happens well above the network layer, however.
UIRequiresPersistentWifi means that the Wifi radio is kept on while you're app is running, even if you don't talk on it. This is important for receiving data. Otherwise you drop off the network and others can't talk to you after about 30 minutes. It should be set in Info.plist, but this is certainly in your app bundle. If it weren't, your app wouldn't launch, so that isn't the problem.
(*) The cell network does have the concept of logged in, but that's not what's causing your problem.