简体   繁体   English

如何在后台触发事件?

[英]How to fire an event in background?

I am having a method called -(void)callTheEvent . 我有一个叫做-(void)callTheEvent

I am writing a code to call the method by using Notifications. 我正在编写代码以使用通知来调用该方法。 But the problem is like until and unless the user tap on notifications the method will not fire. 但是问题就像直到,除非用户点击通知,否则该方法将不会触发。 So here I am thinking to implement like without tapping the notification it needs to fire a method. 因此,我在这里想实现类似的方法,而无需点击它需要触发方法的通知。 Is there any way to implement like this without server? 没有服务器,有没有办法实现这种方法?

Try to use NSObject's methods 尝试使用NSObject的方法

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg;

or 要么

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;

Unless your application is one of a specific category of applications, then your choices are either to schedule a local notification or a remote notification at the specified time. 除非您的应用程序是特定类别的应用程序之一,否则您的选择是在指定的时间安排本地通知或远程通知。 You cannot execute arbitrary code on a scheduled basis while the application in a background suspended state unless it meets specific criteria. 除非应用程序满足特定条件,否则您无法在后台挂起状态下按计划执行任意代码。

Example of applications that can run in the background: 可以在后台运行的应用程序示例:

  • Apps that play audible content to the user while in the background, such as a music player app 在后台播放用户可听内容的应用程序,例如音乐播放器应用程序
  • Apps that record audio content while in the background. 在后台录制音频内容的应用。
  • Apps that keep users informed of their location at all times, such as a navigation app 始终让用户了解其位置的应用程序,例如导航应用程序
  • Apps that support Voice over Internet Protocol (VoIP) 支持互联网协议语音(VoIP)的应用
  • Apps that need to download and process new content regularly 需要定期下载和处理新内容的应用
  • Apps that receive regular updates from external accessories 从外部配件接收定期更新的应用

You can refer to the iOS App Programming Guide , skip to the section beginning with the heading "Implementing Long-Running Background Tasks" . 您可以参考《 iOS App编程指南》 ,跳到标题为“实施长期运行的后台任务”的部分 The criteria noted above are from that reference. 上面提到的标准来自该参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM