How to make NSTimer and some operations keep worki

2019-09-08 04:47发布

问题:

I m writing ios app on 4.3 simulator and 3.2 xcode

The app every minute with timer NSTimer checks news on some websites and if there are news, the app will make alert message with sound "There are something new on ... website!"

But if i close app or it goes to sleep, timer stops on background. So, i have read many articles like http://www.codeproject.com/Articles/124159/Hour-21-Building-Background-Aware-Applications

How keep NSTimer when application entering background?

and non of them helped me. my questions:

1) What technologies or tricks should i use to make such app? One good man told me that i need to use only Push Notifications.

2) If to use Push Notifications, do i have to get Developer Program $100/year from apple and stay my Mac book always turned on for creating server for Push Notifications?

thank you!

回答1:

There are only a few approved uses for running in the background: music, navigation, VOIP. If your app doesn't do one of those things, it can only run in the background for up to 10 minutes, then it will be suspended by the OS.

Push notifications require a server. You either run it yourself, or you use a service like urbanairship.com. A push notification just shows up like an alert on the device. It doesn't make your app wake up, unless the user does it by responding to the alert.

Please read this: http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

If you haven't paid the $100, you can't run your app on a real device. I don't think the simulator properly simulates background states, so debugging background tasks is going to be pretty difficult.