How do I put iOS application in background mode, with audio option set? - iphone

So my application for iphone4 reads data from the accelerometer and sends it to another application via tcp sockets. I need my app to work in background mode, so what I did was:
I put an mp3 file in the application's Documents folder
I used AVAudioPlayer library to play the file in a loop. It works.
I edited Info.plist and added option "required background
modes" with "audio" on.
Still, the scheduler suspends the application whenever I press the iphone's home button. Is there anything I missed?
I read apple's documentation, but I didn't find a solution. A few thoughts on this:
do I have to edit appDelegate.m?
is it because I use AVAudioPlayer instead of the iPod?
is it because I play an audio file from the application documents
folder?
I read about one person changing iOS Development Target from 4.0 to
3.2.1, but that didn't work for me.
And finally, say I get this to work, would the application still be getting data from the accelerometer?
On a side note, I don't want to submit the application to the App Store.

No, you will not receive accelerometer notifications in background mode. As far as I know, it is not possible. Check Executing Code in Background.
If you read the docs carefully, you will know that the whole background code model is based on responding to specific events (location and voip modes).
As for the audio mode here is an extract from Apple:
Your application should limit itself to doing only the work necessary
to provide data for playback while in the background. For example, a
streaming audio application would download any new data from its
server and push the current audio samples out for playback. You should
not perform any extraneous tasks that are unrelated to playing the
content.

Not sure whether you have solved your issue or not since this question was posted more than one year ago. Also, not sure whether playing audio is a must in your app or not. If both answers are no, my recent investigation may help a bit.
Here are how I get my app getting accelerometer data at the background
1. Follow this tutorial http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/ to get the background location working.
2. Follow this tutorial http://jonathanhui.com/ios-motion to get the accelerometer working.
Then you can get an app collecting accelerometer data at the background. Hope this helps.

Related

Swift how to Netflix stop app recording, in plist Restrictions for app recording

Swift how to stop app recording, in .plist Restrictions for app recording, when I am trying to record the app that time I am getting the message, here I attach image please check.
same popup I want to my app
Unlike Camera, Mic & other hardware access that you have to declare them in your's Info.plist file, the screen recording doesn't work that way.
You have to listen of the UIScreen.capturedDidChangeNotification notification and then you have to implement the behaviour of your app based on your needs (like present a info pop up)
In order to understand Apple's implementation I suggest you to read this kind of outdated but to the point documentation : https://developer.apple.com/library/archive/qa/qa1970/_index.html#//apple_ref/doc/uid/DTS40017687
In addition I would follow this guide: https://betterprogramming.pub/how-to-prevent-screen-capture-at-ios-14-1f01173c31c0.
Cheers.

How to avoid suspension of iOS app on background transition?

I know that iOS normally suspends the app on going to background. And there are ways to continue execution mentioned here.
But I found an app Saavn, which continues to download even after going to background.
Although it's a music app, but for audio service to run on background an audio must be playing. And it continues downloading even if no audio is playing.
This also can't be done through beginBackgroundTaskWithExpirationHandler:, as it only allows completion of a single fixed-length task. But in this app it continues to download infinitely till the whole playlist is downloaded.
And I also don't think it would be UIBackgroundModes = fetch because it downloads very large playlists with hundreds of songs(which are definately not samll fetches).
So, is there any other way to continue background execution(without violating apple's policies), NOT mentioned in Apple's developer's reference?
Please refer this documentation, it explains different scenarios https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

Not include functionality that requires that mode to run persistently (key App plays audio)

I have my v 1.1 of my app (iphone) which has been rejected from Apple.
Reasons for rejection:
2.16
We found that your app uses a background mode but does not include
functionality that requires that mode to run persistently. This
behavior is not in compliance with the App Store Review Guidelines.
We noticed your app declares support for audio in the
UIBackgroundModes key in your Info.plist, but no audible content is
played when the application is in the background. While your intention
may have been to provide this functionality, at the time of review, we
were not able to play background audio for your app.
As indicated in the iOS Application Programming Guide: "This key is
intended for use by applications that provide audible content to the
user while in the background, such as music-player or streaming-audio
applications." Therefore, it would be appropriate to provide audible
content to the user while the app is in the background or remove the
"audio" setting from the UIBackgroundModes key.
In the v 1.0 which has been accepted the required background mode "App audio plays" was already enable.
When I launch one sound of my app the sound is played and I when click on the lock screen the sound continues to be played in background.
In the new version (v1.1) I added the function which detects when I push the button Home of the iPhone. If the button home is pressed so the sound is paused.
When i try on my device it's run correctly and without bug.
So I don't understand exactly what is the problem with my app?
If you're pausing the sound when you hit the home button, then you aren't playing a sound in the background. Either change your app so that it plays sound in the background all the time, or email Apple and explain that your app needs the background functionality so that it can play while the phone is locked.
I'm not sure but you might be able to play the sound during the lock screen without audio background mode. Try removing it and see if your app behaves the same. If it does, then you should remove the key (no reason to have it).
If you use the audio background mode, your app has to play continuous audio (like the Music app, or Downcast for example). Is that what yours does? Or does it just play a sound briefly?
You should be able to play a short sound (< 10 mins) by using beginBackgroundTaskWithExpirationHandler: (I think!)
See below the answer to my Question from Apple :
Jul 31, 2012 10:21 AM. From Apple.
Hello,
Thank you for providing this information. However, in order to ensure that the audio background feature is properly implemented, it would be appropriate to press on the home button once the audio is launched.
For more information on how to implement this feature, please refer to iOS Application Programming Guide
Please make necessary change to resolve this issue.

Turning an iPhone or iPod into a wireless webcam

I'd like to stream video from the camera on an iOS device to a receiver via wifi, in effect turning the device into a wireless webcam. Is there a way to build a small app that captures video input on an iOS app and sends it via an RTSP stream or similar?
As this is an ad hoc experiment, I'm not concerned about App Store guidelines and can jailbreak if necessary.
If I interpret your question correctly you more or less need to solve four problems:
Get the camera feed.
Convert/encode this to the right format.
Stream the data.
Prevent the phone from locking itself and going into deep sleep.
The first one is fairly simple and Apple has as always provided good documentation and examples -> API link. Make sure you check out their example in the end as you will get a CMSampleBufferRef data object back.
For the second and third part, you should check out the CFNetwork framework and specially CFFTPStream for streaming using FTP.
If your are only building this for yourself then you can always turn off the Auto-Lock feature in the settings. If you on the other hand would like to distribute this to other users you could use a trick to play a mute sound every 10 seconds. This is more or less how all the alarm clocks work in the App Store. Here's a tutorial. =)
I hope I helped a little bit at least.
Good luck and best regards!
I'm 70% of the way to doing the same thing. Here's how I did it:
Capture content from video input
Chop video into files for use in HTML Live Streaming.
Spin up a web server on the iPhone and make the video files available.
Connect to the IP address of the phone and viola! you've got live streaming video.
Last time I touched the code I was trying to debug my Live Streaming not working. I'll try and get my source code posted on github this weekend, if you'd like to take a look.

iPhone SDK - HTML Live Streaming for audio

I've been developing an iPhone application that streams audio using Matt Gallagher's audio streamer found here: GitHud: AudioStreamer
However, I'm having some problems when the iPhone loses internet connection because the stream cuts out and doesn't reconnect until the user actually presses the play button again. I've even tried using the reachability classes from Apple to try and automatically stop and reconnect the stream but this isn't working 100%.
I've been reading around on the internet and I've found something called HTTP Live Streaming that can supposedly be used to stream audio on the iPhone. However, I can't seem to find any examples of how to use this, therefore can anyone help me by given a brief description any any source that might help to get this working please?
Thanks in advance,
Luke
Not enough detail for me to answer this entirely, but I use a set of calls
to be notified of reachability changes.
When I get a failure, I change the play image to stop.
I then wait for a notification that the network is back
and then programmatically press play for the user.