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

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

问题描述

我有一个类名,因为 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.

更多关于后台:应用状态和多任务处理

声明您的应用支持的后台任务

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 — 即使在后台运行,该应用也会让用户了解他们的位置.

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 — 该应用是一款报亭应用,可在后台下载和处理杂志或报纸内容.

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

external-accessory — 该应用与需要定期提供更新的硬件配件配合使用.

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

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

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