iPhone SDK Internet connection detection - ios

I'm working on an iPhone application that makes a few calls to web services. I posted this application on the Apple store but it got rejected (and rightly so) since there was no error message displayed to the user if no Internet connection is available. Since obviously the application would not work without it.
So I just wanted to know how to best achieve this? I'm guessing something needs to go in the viewDidLoad method that will throw an alert box saying something like "You need an Internet connection to use this application".
Any ideas would be appreciated.

If your application must have network access the easiest way is to add the following settings to your info.plist as boolean values.
SBUsesNetwork - Ensure the device has an active connection (Edit: not applicable, this seems to be a private API someone found at some point. It is not in Apple's developer documentation.)
UIRequiresPersistentWiFi - Ensures the device is connected via WiFi
If your choice is not true then the user will be presented with an appropriate message when starting your application. Best of all this message is from the OS and thus is localized.
If your application cannot download data from a website while running (loss of signal, site down) you should still warn the user though and not just spin indefinitely.

Apple Developer Connection has a sample application (Reachability) that uses the System Configuration framework to determine network status. It will tell you whether you have a WiFi, EDGE/3G or no Internet connection.
You would use portions of this code in your application to determine network state, and then provide interface cues if no connection is available, such as a UIAlertView.

Cautionary word: beware SBUsesNetwork. I would personally love to know where SBUsesNetwork originally came from, because it's not mentioned anywhere in Apple's docs that I can find. When I add the key to my app's plist (as a boolean) and set to true, it doesn't seem to affect the behaviour of my app -- I get no warning about airplane mode, whether starting app completely afresh, or foregrounding a previous launch that was backgrounded.
My app has UIRequiresPersistentWifi set to true, which appears to also do the job people claim SBUsesNetwork does (plus other things!).
(I'm running iOS4.2.1 on an iPhone 4, XCode 3.2.5 64 bit).

Related

App rejected due to an IPV6 Swift3 error. How do I fix it?

A few days ago, Apple rejected my app, indicating that it didn't have IPV6 support, however I don't need that support since my app does not require internet access.
I asked the following:
Hi, my app does not need any internet connection yet.
So, why it's required to have support to IPV6?
They said:
Thank you for your response and for your question. In order to bring your app into compliance with Guideline 2.1 it would be appropriate for your app not to crash when logging in.
end
So, why do I need that Support?
If is necessarily, how do I can do it?
Please I need help
Test your app extensively and fix the crash. Enter wrong values, don't enter anything at all, intentionally try to break your app and get it to crash. Then you will find your error and you can fix.
EDIT BASED ON COMMENT BELOW
"My app don`t need conect with external database, because I got the information inside" - in this case, no, you do not need to add IPv6 support because you are not communicating with the internet for logging in purposes.
You can keep the login given it is only going to be 2 people using the app, just resolve the crash when logging in.
To test, enter a variety of incorrect passwords and usernames to ensure that there is no crash on incorrect entries, and confirm that correct entries do not crash the app.
Original Answer
Apple indicated that because there is a login feature, they think it is trying to communicate with an external database (ie a database that is not on the device). If there is no external database, just fix the crash is what they are asking.
Based on your question, you have eluded to the app not communicating externally for logging in. While some may find this odd, it is not uncommon. An example for those wondering would be a childrens app for iPad. The iPad might be shared amongst several children and as such each child might complete different sections or features of the app so an account local to the device is a good idea if there is no cloud support.
If there is external communication, you need to handle the case for no internet access. The question has been answered extensively, however this was the first result I found:
Detect Internet Connection and display UIAlertview Swift 3
Update: Why do I need to Support the case for no internet connection?
A use case:
John has just downloaded your app. He has just walked through the steps to create an account, but he has accidentally set his device to Aeroplane Mode.
John hits the "Create Now" button but nothing is happening. There is no error or success alert appearing, the screen has not changed, he can't see a loading icon. John is confused and getting frustrated because he's certain that he has completed everything in the form.
John doesn't understand that he needs internet connectivity to successfully submit a request to create an account. John decides to delete your app from his device and leaves a bad review.
John really could have used an alert saying "You need internet connection to sign up to this app. Please check you are connected and try again". This would have made John a whole lot happier and he probably would have continued to use your app with all of it's amazing features.
More information can be found in the guidelines that Apple mentioned, and further to this, the Apple Design Principles Guide is an invaluable resource.
I hope this makes sense.

AppStore: will app relying on network be approved?

I develop a well-looking professionally designed application, which loads events for some clubs at startup (it has more functionality, but all require network connection).
If there's no internet access, app shows "Error: No network access" message with OK button. It exits when user presses this button.
Will it be accepted in App Store? If no, what should I change?
Thanks! :)
This is an opinion question, but my experiences suggest:
It's OK that your app requires network access to provide meaningful content.
Do NOT forcibly terminate (exit) your app in this case, but instead show a helpful message, and keep polling the network status (ie use something like Reachability). If and when the network connectivity comes back, remove the message and proceed.
Bonus points: If you can cache data from when there is a connection, then you can run the app anyway showing the most recent data you have. This is generally preferable as a user experience to simply blocking access to the UI if you can't get to the internet.
Do not exit the application.
If your app work only if network is available, that's okay. But if network is not there, it would be better if you show an empty view with proper message (That for this app, network is needed or something like that. Add some error images or graphics it'll improve the user experience also). Don't forcefully close the app, it can be consider as a crash(Apple will reject your app).

Can I connect single MFI accessory with two apps at a time

I have two apps with same UISupportedExternalAccessoryProtocols. These are communicating with the MFI certified device. How I can know that the session is already created with other app on the same device. So I can alert to the user that you can't create multiple sessions with the same accessory at a time.
Please help to fix this.
Thanks in advance.
I personally consider AyBayBay's answer invalid, since you tagged your question with the "iOS tag" and NSDistributedNotificationCenter is not supported on this platform. (There is a low level api to do this, but I think it's in a private framework)
If you are pretending to target your app to iOS8+, the simplest way to do it is using iOS8's AppExtensions feature. I made some tests creating a session within my app, and sending info to the device from another app using extensions the way below.
some app -> app extension -> my app connected with ext.device -> ext.device
so I'm pretty sure you can check if the session is opened or not and return this info to the caller app.
FYI: To pass info to another app you can also use URLSchemes or UIPasteboard too, but both behaviours in a different way than AppExtensions and I think it not fits on your case. Maybe it helps someone else...
Well when one app connects and establishes a session with your MFI device, you can post a notification to NSDistributedNotificationCenter. Your other app can subscribe and listen for this message, upon recieving it and processing it in its runLoop (when it comes back into the foreground) you can have code that blocks it off from creating a session at the same time. You will have to experiment with this a bit but it can be done.

Cordova - opening the InAppBrowser without checking for a network connection (Apple Approval)

I'm not entirely sure why I feel this way, perhaps something I read at some point, but my understanding is that while providing an offline experience within an app, it is my responsibility to appropriately manage situations where my app requires an internet connection and one is not available (a proper alert for example).
When opening an external website using the Cordova InAppBrowser, if there is no internet connection, am i required to do something about it, or is the error appearing in the webview of the plugin enough? Will this interfere with the approval process, or is this entirely ok?
Check this out Dom.
http://gtproductions.net/blog/ways-to-get-rejected-by-apple-app-store-tips/
point 4 seems to point out that apps (games here) may get rejected if connection issues are not properly handled.

Counting missing calls on iPhone/iOS

I'm quite new at iOS app development.
I'm starting to work on an app that should in somehow be able to count the missing calls that the iPhone has registered since the app is running.
I've read that in no way Apple is going to let me intercept incoming calls, answer them, reject them, or "whatever" them, but I wonder if we are allowed to count them.
I've found some people that say it can be done (well, I knew it is possible, cause LockInfo does, for instance), but I don't know if it's attached to jailbroken iPhones only.
Anyway, as far as I have seen, it must be done with some methods related to kCTCallStatusChangeNotification from CoreTelephony.h if I'm right (as seen in http://blogs.oreilly.com/digitalmedia/2008/02/when-it-comes-to-the.html), but I coudln't find much more info about it.
Hello and welcome to iPhone Development! :) As you have already pointed out, you can be informed through a notification if a call is happening. Great! But here comes the dark side of iPhone Development:
That's the end of the road. 95% of the "Phone Functionality" of the iPhone is private API and you don't technically have access to it.
Of course, you could header-dump the private frameworks and use them anyway, but that will get your app instantly rejected from the AppStore, which wouldn't be fun for anyone.
LockInfo is an extension for jailbroken devices - those guys are known for not caring too much about Apple nor Private APIs ;) Also, as you may have seen, LockInfo isn't on the AppStore because it would've never made it that far.
So Apple, why is there CoreTelephony?
Well, it's there for some very specific reasons. I personally use it to obtain the carrier name of the device for certain country specific restrictions in my application. The notification you talked about, along with others, tend to be used by developers to prepare your app for going into an inactive state (when the call comes in, your app is put in the background), so its used to pause tasks etc... CoreTelephony has never been intended for any deep level access to the telephone system of the iPhone.
So sorry, you can't obtain the information you're looking for using public APIs.

Resources