iPhone background notifications - iphone

I'm making an iPhone app. I can receive UDP messages using AsyncUdpSocket. I want the app running in background, and when receive a message, an UIAlertView is displaying to the user, and he can enter in the app, or ignore the alert.
Is it possible to detect a message when the app is running in background.
Do I need something to execute my code in this method?
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
I saw lot of tutorials, with timer, but I don't need timer to wake up my app. Also I read that's it's possible while playing music, tracking position or using VOIP.
Do I need to play a fake song to keep my app running? or to do something like that?
This app is for security, for example if someone is touching or moving your motorbike/computer/whatever else, your iPhone can alert you and prevents from stealing.
I read other threads similar but didn't find an answer.
Thank you guys for giving me tips, or any help /sample.

You can't run in the background on a non-jailbroken phone without being in one of those three categories of app, and Apple’s really unlikely to approve your app if you use that facility for another purpose. UDP probably isn’t the best solution for this anyway—if your phone leaves the network that the other device (whatever it is) is on, it won’t receive the notification at all, whether or not it’s in the foreground. You’re probably a lot better off using the push notification API.

This seems like a perfect case to use Apple Push Notifications (APN). You app can register to receive the notifications and the phone will alert the user with any combination of badging, messages, or sounds. Sounds like you already have a server that is sending the UDP messages, so incorporating APN should be minimal. Especially if you use a third-party to send the push notification, such as Urban Airship. (I am not affiliated with them, but have used them on a large commercial project.)
By definition, local events are not triggered by receiving a message.

Related

iPhone background operations/daemon with live chat module. Keeping the app alive?

I am building a live chat app for the iPhone, and for this it is necessary to ensure that the operator is online and to keep the flow of data going.
After much search it seams to be only two options for similar kind of behavior;
UILocalNotification, only works if I have some scheduled information notice to be sent
Push Notification, for pushing data to the phone
The problem with push notification seams to be that I cannot ensure that the user is available, or in any way talk with the app without the user re-opening it. This way it seams impossible for me to know if the user is online, to update data in the app without the user having to manually open it, etc.
So, what I ask for, is it in any way possible to keep the app active in the background thus ensuring the operator is online and notify of incoming chat sessions?
Thanks a lot for your help guys!
Unfortunately the answer is no. I take it you mean text chat and not VoIP (which CAN run in the background)? Your best bet would be Push Notifications, as you would not be able to monitor anything from the app itself when it is in the background.

can we send messages to user even when the application is closed in iphone sdk?

i m making an application where data is accesed from website and displayed with an application.i have made an action which will tell the user that new data has arrived.this will work properly if the application is open .but if the application is closed than ,is there any way to tell the user that new data has arrived ,,so that he can open the application and check the data?
If you are using the Apple Push Notification Service (APNs), your messages will be delivered whether the application is running or not. For information on how to control what information is presented to the user, read the Apple Push Notification Programming Guide.
You should use Apple Push Notification Service, like codelark said.
I would recommend looking into Urban Airship for help getting started. It's a third party service, but it makes things much easier. Urban Airship does have their own tutorials and code samples which may be easier than Apple's.
As a follow up to the reference to apple push notification, as of ios4.0 I believe you, you may have a few more options, 1) you can send local notifications (just like push notifications, but they originate from inside your app) that could be timed to be delivered even if the app is not running..assuming you know approximately how long it will take for data to arrive. 2) if your data update will occur soon after the app closed.. your app can request a certain amount of time to complete an operation (even though the user has closed the app) and wait for the data, then send a local notification to tell the person to come back into the app. 3) if your functions based on gps updates, music streaming, or voip you can set a flag so your app continues to run in the background
sorry for the unstructuredness of the answer, this was just off the top of my head, hope it helps

Iphone App - Is it possible to use text from an app?

Hey, I am about to start working on an app. I am a beginner, so I am starting out with a pretty basic concept. But, I was wondering if it was possible to send texts from an app. For example, if the person using my app sets a new high score, could they hit a publish button and my app could then send a text to his buddy bragging about the new high score.
Also, what if someone is using my app and they receive a text, does the OS take over, or do I have to handle the reception of text/calls. Is it possible to alter the way the phone behaves when my app is disrupted by calls/texts.
Thanks for any advice you can give. Have a good Monday everyone!
Apple's iOS documentation has a section that roughly covers how to incorporate in-app SMS.
Basically, your application displays an MFMessageComposeViewController as a modal view controller. It won't cause your app to terminate or background — it just lets your user send a text message, and when done, return to your app and continue.
When a phone call, text message or another notification comes in, your application delegate's applicationWillResignActive: method is called. It's up to you what you want your app to do while the user is dealing with the call, message or notification. If the call is declined or the alert dismissed, your application delegate's applicationDidBecomeActive: method is called and your application can resume as if nothing happened. Otherwise, the app either exits or backgrounds (depending on whether you want it to support multitasking), and you'll also have to handle it from there.
Also bear in mind what Toastor says about
Controlling whether messages can display to your user or not
Bills related to texting plans
There is no way to change the way the phone responds to calls. The only way to prevent your app from being interrupted by an incoming call is by activating the airplane mode on the device - which you cannot enforce from within the app.
Same goes for incoming texts - there is no way to notify your app if a message has been received. How would the system know if the message is meant for your app anyway?
The only thing you can actually do is send a text message from within your app. But if I were you I'd go either with established leaderboards or the new GameKit (have not checked this out yet myself, though).
Or, at least, use mail instead of text messages, since texts are not free in every country.

Question regarding iphone allowance of custom notifications

I have an app that I am working on, and part of its main functionality is to alert the user to do something. So even though they aren't in the app, I want to be able to pop up an alert from the app, reminding them to do something. Is that allowed with the iPhone sdk? Maybe it isn't even a big deal at all, but for some reason I was thinking that it would require background processes or something that may or may not be possible. Anyone who has any thoughts about how this would be implemented would be greatly appreciated. Thanks!
Check out the Apple documentation on push notifications. Short of jailbreaking and distributing your app outside the App Store, there is no way to run background processes at this time.
It is allowed through notifications, though you will need a server to actually send the notifications to the user. There is no limit to the number you can send, although the user may very well decide to shut off notifications or delete your app altogether if you are too spastic with them. Make very sure the user understands the notification volume they will receive and agrees to it...
The way the system works is the user gets a notification message (and/or sound) and can decide to open your app or not, as the time of notification.

Can I use Push Notification for this

My app should post some message to Twitter at the end of each day at the time X. App might not be running at this time X, but it still has to post that message. I don't want to bother user by everyday asking to do this task.
Can I use Push Notification to silently (without any alert view popup, sound or anything else) do some task in my app in some constant time everyday even if it's not running?
thx
There are three 'notification' mechanisms you can send via push: alerts, sounds, and badge values. The way the push notification works is that on the phone it launches the app and hands over the 'push payload' to it with those values. Even if you turn off all three mechanisms, the OS will still have to launch your app each time, which means the user will get interrupted.
In short, you can't have a push happen silently. I doubt, from a user-experience point of view that Apple will allow things to happen on the phone without the user getting notified somehow.
No.
You can't schedule things to be run by your app on a non-jailbroken iPhone.
The only solution is to have a separately hosted service somewhere to which you push details from your app and that runs the scheduled updates on your behalf.
To do so silently is not up to you. The iPhone device has a configuration in which each app with a Push mechanism has settings where one can specify if they want alerts or not. If set to yes, the text of the alert is displayed as well.
sounds like you are trying to "wake up" your app at a specific time each day to perform some type of task. from what i understand about the iPhone this is not possible. you cannot create a cron job or something that will fire on a time you specify. you can run this on the server side and then push a notification to the user telling them that the message has been posted to twitter.
if you are on a jailbroken phone i feel confident that there is some way to do this.
Given that push notification requires that your server send a notification, why not skip a step and have the server just send the update directly to Twitter on the user's behalf? You can't use push notification to trigger an automatic task on the iPhone like you're asking - the user must take the step of accepting the notification for anything to happen.
if you really want to do it from the phone, you can just declare a "long term" background task should be covered around here (iphone app programing guide) some where..., that way you never go sleep, and you can do what ever you like... :)