如何让 NSTimer 和一些操作在后台继续工作? [英] How to make NSTimer and some operations keep working on background?

查看:72
本文介绍了如何让 NSTimer 和一些操作在后台继续工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 4.3 模拟器和 3.2 xcode 上编写 ios 应用

带有计时器的应用程序每分钟 NSTimer 检查某些网站上的新闻,如果有新闻,应用程序会发出带有声音的警报消息...网站上有新内容!">

但是如果我关闭应用程序或它进入睡眠状态,计时器会在后台停止.所以,我已经阅读了很多类似的文章http://www.codeproject.com/Articles/124159/Hour-21-Building-Background-Aware-Applications

​​应用进入后台时如何保持 NSTimer?

他们都没有帮助过我.我的问题:

1) 我应该使用什么技术或技巧来制作这样的应用程序?一位好心人告诉我,我只需要使用推送通知.

2) 如果要使用推送通知,我是否必须从 Apple 获得 100 美元/年的开发人员计划,并让我的 Mac book 始终处于打开状态以创建用于推送通知的服务器?

谢谢!

解决方案

在后台运行只有几个被批准的用途:音乐、导航、VOIP.如果您的应用没有执行其中任何一项操作,它最多只能在后台运行 10 分钟,然后它就会被操作系统挂起.

推送通知需要服务器.您要么自己运行,要么使用urbanairship.com 之类的服务.推送通知只是在设备上显示为警报.它不会唤醒您的应用,除非用户通过响应警报来唤醒.

请阅读:http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

如果您还没有支付 100 美元,则无法在真实设备上运行您的应用.我认为模拟器不能正确模拟后台状态,因此调试后台任务将非常困难.

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!

解决方案

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.

这篇关于如何让 NSTimer 和一些操作在后台继续工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆