How can I call Method while app is in background in iOS?

前端 未结 3 1114
臣服心动
臣服心动 2021-01-23 16:18

I have one class name as myClassCalculate have the following method

- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)accel         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-23 16:55

    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

    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 — 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 — 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.

提交回复
热议问题