当应用程序在iOS中处于后台时如何调用Method? [英] How can I call Method while app is in background in iOS?

查看:119
本文介绍了当应用程序在iOS中处于后台时如何调用Method?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类名称为myClassCalculate,具有以下方法

I have one class name as myClassCalculate have the following method

- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

NSLog(@"Accelerometer is called");

}

我在做对象

    - (void)applicationDidFinishLaunching:(UIApplication *)application {    


    // Override point for customization after app launch
       myObject = [[myClassCalculate alloc] init];

现在应用何时在后台运行,我想要这个

now when app will go in background, I want this

    - (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

我该怎么办,这样该方法才能在应用程序后台调用

What can I do, so that this method will get called in app background

谢谢

推荐答案

您不能,仅允许VOIP,音频和导航应用程序在后台运行。
因此,如果您的应用程序不属于这些应用程序之一,它将被暂停并且不会收到任何事件。

You can't, only VOIP, audio and navigation apps are allowed to run in background. Thus if your app does not fall in one of these it gets suspended and wil not receive any events.

有关背景的更多信息:应用程序状态和多任务处理

More about backgrounding: App States and Multitasking


声明应用程序支持的后台任务

Declaring Your App’s Supported Background Tasks

支持对于某些类型的后台执行,使用它们的应用必须提前
声明。应用程序使用其Info.plist文件声明支持
服务。将UIBackgroundModes键添加到Info.plist文件的
并将其值设置为包含以下字符串中的一个或多个
的数组:

Support for some types of background execution must be declared in advance by the app that uses them. An app declares support for a service using its Info.plist file. Add the UIBackgroundModes key to your Info.plist file and set its value to an array containing one or more of the following strings:

audio -应用程序在后台播放可听内容。 (此内容包括使用AirPlay流音频或视频内容。)

audio — The app plays audible content to the user while in the background. (This content includes streaming audio or video content using AirPlay.)

位置-该应用程序可让用户随时了解他们的位置,即使它在后台运行。

location — The app keeps users informed of their location, even while it is running in the background.

voip —该应用程序使用户能够使用Internet连接拨打电话。

voip — The app provides the ability for the user to make phone calls using an Internet connection.

报亭内容-该应用是报亭应用,可在后台下载和处理杂志或报纸的内容。

newsstand-content — The app is a Newsstand app that downloads and processes magazine or newspaper content in the background.

外部附件 —该应用程序与需要定期提供更新的硬件附件一起使用。

external-accessory — The app works with a hardware accessory that needs to deliver updates on a regular schedule.

这篇关于当应用程序在iOS中处于后台时如何调用Method?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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