Does apple allow sound detection when app is in background? - ios

In one of my apps I have to detect external sound even if the app is in the background. I have some question on this.
Is it possible to detect external sound continuously even if the app is in background mode or closed? If so then will it have an effect on the device battery?
Does apple allow these kinds of app?
If my first question is not possible then is there any alternate way to achieve this?

It is impossible to detect the external sound when the app is in background.Due to background task time restrictions, iOS Background Task can not be run more than 10 secs.
app is not possible.
You can make notifications while the app running in background. But I dont think any way to achieve this functionality.

This is not possible.But you can make it only for some secs.
With Push Notifications it is possible.

Related

Show advertisement at regular interval of time when iPhone is running

I am working on the app that shows Ads (Video or image) when iPhone is running. If I open any app(eg. Twitter) then also my Ads should be visible at particular interval of time. Is it possible to do so?
No. Your app will not be informed about any other apps being launched. Even if it were, you can't "force-grab" the foreground to display videos. That would totally violate any user interface principle established by iOS.
Besides the technical aspect I'd have my doubts of such an app surviving app review in general, though I don't know the specific part of the TOS right now.
It is possible to show your ads inside your application in intervals or in any pattern you like. However it is not possible to bring your app to foreground when in background to play ads, it is actually not recommended at all. Best thing you can do is set a timer when the app gets in background to send a notification.

iOS:how schedule the app from background to foreground

I am coding for connection between iPhone and my smart watch by bluetooth low energy. The functionality is "find my phone", touching the watch then iPhone will alarm. During the process, I want to my app will being active. It can be scheduled to the foreground from the background, so we can do more other thing! But I am not able to find the api about it, anyone can help me, thanks?
You can not force an application to bring it to foreground.
Please see this answer for help.
https://stackoverflow.com/a/22930371/1891327

iOS background service vibrate phone

I have an app that runs in the background (location services). When the app is in the foreground it vibrates fine when I want it to, however, if its not in the foreground (in the multitasking view), the vibrate does not work anymore. Is this not allowed? Is there some way for my background app to give a vibrate alert? If not that what about a beeping sound?
Right now I am just doing something like this:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
While importing:
#import <AudioToolbox/AudioServices.h>
If you enable background audio modes (as documented by Apple at https://developer.apple.com/library/prerelease/ios//qa/qa1668/_index.html) then vibration will happen when the app is in the background state. I just verified that adding the "App plays audio or streams audio/video using AirPlay" entry under the "Required background modes" property in the target's properties allows the vibration to work when the app is not in the foreground.
I found that checking 'Audio,AirPlay and Picture in Picture' within the 'Background Modes' of your apps Capabilities worked:
If you're trying to provide the user with a notification of something while your app is running in the background, consider delivering that information using a Local Notification (see UILocalNotification.)
Forcing the phone to vibrate is not a great user experience for a few reasons:
Some users (including myself) disable vibrate while in silent mode
iPads and iPod Touches do not vibrate
Users may not know what caused the vibration or sound and may not realize to open your app
Local notifications appear to the user in a manner that they can control and will recognize.
If your intention is something besides notifying the user, add that to your question & I'll try to help.
I'm pretty sure that you aren't able to vibrate the phone while it is in the background state. I've actually never seen an app do this.

Invoke the application to play a music on receiving a push in iOS

I implemented Push notifications in iOS. I want my application to play a music (about 15sec) when I send a push message. I am currently getting the push message, and the music is being played only if the app is in the foreground.
If the app is in the background, it shows up a notification, and when i tap it, it then plays the music.
But how do I get the functionality of automatically playing the music? I think this can be done because, in iOS, Audio apps can run in the background. So I just want the music to be played when the app goes to background, and it receives a push.
Can anyone help me with this please?
Thanks,
Nithin
Yes, there are two ways to do this.
The traditional way before iOS 7 is to register for audio playing background mode and play a silent sound forever, this will keep your app running in the background for a long time until the user kills it, or it is killed due to low memory.
This way has many drawbacks, the user must launch your app once so that you can start playing the sound and every time the iPhone is shut off, the user need to relaunch your app when he turn on the iPhone.
Also this will consume a lot of battery. 20%-30% a day for an iPhone 5.
The new way after iOS 7.0 is to exploit background fetch and remote notification, you can play your sound while performing a background fetch, which has a 30 seconds running time. Also you can trigger a background fetch with a push notification.
This is an article about background fetch and push notification http://www.objc.io/issue-5/multitasking.html

iOS: Detect screen on/off events

I'm trying to detect screen on/off events from a background service on iOS.
Because my app is not necessarily in the foreground, looking for app lifecycle events such as this aren't any use:
Lock Unlock events iphone
The best solution I've got so far is to search through the system logs, looking for Springboard events. Problem is, it's a pretty expensive operation, and requires regular polling which is a waste of battery. The solution needs to work on non-jailbroken devices but doesn't necessarily need to be app-store approved.
Can anyone suggest something better?

Resources