Play background music would be rejected by Apple Store? - ios

I produced a pedometer program in ios.I want it can work in the background,But I found it would interrupt finally.So I add a AVAudioPlayer and play a silence music when in the background and it works right.
Now I want to submit to the App Store.I worried that I would be rejected.can anybody tell me about sth?
If this way doesn't work,How can I run a pedometer in the background?
(ps)I need to support the device without M7

Yes you will be rejected. You cannot do tricks like that just so you can have your application run in the background. It's like declaring your application as a VOIp app just so you can run background processes.
I suggest you have a legitimate feature that requires the background process otherwise your application will be rejected.
Have a look at this link and search for the heading UIBackgroundModes to see the 6 UIBackgroundMode keys:
UIBackgroundModes (Array - iOS) specifies that the app provides specific background services and must be allowed to continue running while in the background. These keys should be used sparingly and only by apps providing the indicated services. Where alternatives for running in the background exist, those alternatives should be used instead. For example, apps can use the signifiant location change interface to receive location events instead of registering as a background location app.
I do feel that you can have your application run in the background if you use some location services in your application. Then, quite possibly, could you register your application under the location's key:
The app provides location-based information to the user and requires the use of the standard location services (as opposed to the significant change location service) to implement this feature.

Related

Does iOS have something like Android's AlarmManager?

What is iOS' alternative to Android AlarmManager class?
So far the closest thing that I found is NSTimer. But that works only when your application is up, once it goes to the background it won't work, and I need to run some function in the background and from my business logic to decide if I want to do something or not. For example if some condition is satisfied to display local notification.
The only workaround I found is to use remote pushing notifications (silent notifications) just to wake up app, and from there you can implement your business logic.
IMPORTANT NOTE
From what I have found on few places is that people are complaining about using silent notifications to do this because your application might be rejected on app store.
There is none.
As already stated in the comments, the documenation is quite clear on that:
Always try to avoid doing any background work unless doing so improves the overall user experience. An app might move to the background because the user launched a different app or because the user locked the device and is not using it right now. In both situations, the user is signaling that your app does not need to be doing any meaningful work right now.
with the following exceptions:
For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
There is no exact equivalent. Please read this: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
The relevant part:
For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services. Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.
If the function you are trying to call does one of the above, the documentation explains how to use background tasks or other methods to accomplish that.

How can I capture the accelerometer data on iPhone when the app is in background?

In an iOS app, by enabling the flags for VOIP, Audio playback, Location, Bluetooth LE accessories, News stand etc, we can run the app in background. But I've a requirement to create a library/framework that will make the app run in background as well as capture the accelerometer updates and log them to a file.
For that purpose, I enabled "Audio Playback" in the background, and playing a silent file in continuous loop so that app will continue to run in background. At the same time, I'm able to capture the accelerometer data as well. I'm using Core Motion framework for the same and its working perfect.
I would like to add one more point, my app has location tracking enabled to deal with beacons integration.
I want to know if its valid to follow such procedure and will Apple approve it during the review process? Has any one faced this kind of challenge ever?
As you guessed, the only way to access accelerometer data in background is with an active background mode. But...
Apple will NEVER accept your app if it declares a background mode without any feature actually using it (not just technically like your silent sound, but an actual feature that your user is aware of)
If you decide to implement a feature that actually use a background mode (like location or audio playback for example), don't forget that you will also drain your user's battery.
Conclusion:
Explain to your client that Apple's restrictions prevent you to do that and have the requirements updated
or
Find another feature that will need to use one of the background modes

iOS app to run continuously in background

I want my iOS apps to run continuously in background 24/7
I tried many options like background location updated with background task expiration handler, but later after some times it seems that the application gets suspended in background and user is brought back to the root view controller.
Any help will be appreciated.
For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Ap ps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services.
Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.
You should read this page of Apple Programming Guide : Background Execution
It is not allowed to run background tasks 24/7. But you can use many different ways.
You simply can't. Apple don't give any mean for an app to ensure background execution. iOS will give you processing time whenever it feel like it, and you cannot control that.

How do iOS chat apps keep running in the background?

I have always coded for Android, and now I'm looking to expand my knowledge to iOS development; so I'm really new at this, please be patient.
I understand that only a small group of apps are allowed to run indefinitely in the background. Those are VoIP, Music players and location tracking apps.
I want to write a chat app using the XMPP framework. Everything is fine until the user puts the app in the background, in which case, the app will stay connected for about ten minutes to then be killed by the system and therefore the user won't be able to receive new messages.
I am aware of hacks to keep the app alive. Hacks such as defining it as a music playing app in the info.plist file and then just play some empty sound indefinitely. But I'm also aware that Apple will reject the app when it's time to publish to the App Store.
So, normally, how do other apps do it? How can other chat apps stay alive in the background to receive new messages from the servers? Apps like Google Hangouts, IM+ and such?
Ideally, they aren't really running in the background, but use push notifications, as others have mentioned.
But some chat clients seem to do something else: I've verified (by sniffing the traffic of an idle iOS device) that at least Google Hangouts, Facebook and Skype all keep a persistent socket opened in the background, and regularly send traffic to keep it alive.
I'm suspecting that they are using the VoIP exceptions to Apple's otherwise strict background execution policies. iOS allows "VoIP apps" to run in the background and keep one socket open to be notified about incoming calls and messages.
Maybe they are also using the new "background fetch" feature of iOS 7, but as far as I know, that doesn't allow persistent socket connections.
The iOS operating system allows for the existence of something called a PUSH NOTIFICATION
There exists hundreds of tutorials online which teach you how to implement the notification code and how to respond accordingly when you receive such a message!
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
Check this link out for an in-depth tutorial on push notifications!
http://maniacdev.com/2011/05/tutorial-ios-push-notification-services-for-beginners
I think most of these apps use push notifications and just load the last messages from the server as soon as the app is being opened.
While there are some hacks, and your app can ask for more time when it goes in background (up to a point, and with no guarantees), this is a perfect application for push notifications.
The server tells the phone there's a message, and iOS wakes your app up to process it.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html
As of iOS 7 there is a new background-execution mode - 'fetch' for apps that need to periodically fetch new data. It sounds like your case would meet that definition.
You can find the information in the iOS App Programming Guide -
Fetching Small Amounts of Content Regularly
In iOS 7 and later, an app that retrieves content regularly from the
network can ask the system for background execution time to check for
new content. You enable support for background fetches from the
Background modes section of the Capabilities tab in your Xcode
project. (You can also enable this support by including the
UIBackgroundModes key with the fetch value in your app’s Info.plist
file.) At appropriate times, the system gives background execution
time to the apps that support this background mode, launching the app
directly into the background if needed. The app object calls the
application:performFetchWithCompletionHandler: method of its app
delegate to let you know when execution time is available.
You can also use push notifications, but that requires some server infrastructure
An app running in the background has limited capability. Read App States and Multitasking thoroughly to decide how best to design your app. Chat is not listed as one of the specific exceptions that can operate with a more relaxed policy. You will never be able to "keep [your] app live in background forever." You might be able to leverage an iOS 7 feature also described in this guide, Fetching Small Amounts of Content Regularly.
iOS App Programming Guide: App States and Multitasking
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOS ProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

Show some UI from background in audio player or VOIP app on iOS

I know that audio players and Voip apps can run in background on iOS.
Is there a way to show UI from background (except LocalNotifications)? I mean full screen UI.
A method which uses private API or other tricks are acceptable. The application will be signed with enterprise certificate and won't be deployed/reviewed by AppStore.
A method which works only on jailbroken iOS device isn't acceptable.
Check out this document and search for "Implementing Long-Running Background Tasks" Basically you need to register your app to run in the background instead of being suspended and listen for notifications.
from the docs:
" An app declares support for a service using its Info.plist file. Add the UIBackgroundModes key to your Info.plist file" and ".....values lets the system know that your app should be woken up at appropriate times to respond to relevant events."
http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20
Victor, have you tried some trick like defining a custom URL for your App?
Springboard can start applications when parsing custom URLs; if they are in background they become foreground.
You must create a URL type into your app's info.plist in the key CFBundleURLTypes, for example "mySpecialURLType". Your application delegate also have to implement handleOpenURL: and openURL:sourceApplication:annotation:.
If you (in your background task) ask for a URL like "mySpecialURLType://", theoretically SpringBoard will start your application.
I don't know if it works, but is worth a try...
Best!

Resources