iPhone background notifications
I'm making an iPhone app. I can receive UDP messages using AsyncUdpSocket. I want the app running in back开发者_如何学编程ground, 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.
精彩评论