简体   繁体   中英

Record swipe amount when app is in the background iOS using Swift

I have been looking around for a solution and found only specific apps have background capabilities ie locational data and playing music. Assuming we have this permission, is there any way to record the swipe amount from all other apps and home screen, etc? The end goal is to record (in total) how far a user has scrolled using Swift.

So far, I have tested in app and can record a running total. However, is it possible to achieve this even when the app is inactive?

import UIKit

//test variable for storing scoll amount
var counter2 : Int = 0;

class ViewController: UIViewController {

    @IBOutlet weak var sCounter: UILabel!
    @IBOutlet weak var sMeasure: UILabel!
    @IBOutlet var scrollMeasuer: UIPanGestureRecognizer!

    @IBAction func scrollCounter (recognizer : UIPanGestureRecognizer) {
        //var counter : Int = 0

        let translation = recognizer.translationInView(self.view)
        sMeasure.text = "\(translation)"

        counter2 = abs(Int(abs(translation.x) + abs(translation.y)) + counter2)
        sCounter.text = "\(counter2)"
    }
}

No you cannot do this.

When in the background your views are not displayed and so swipes will not be recorded by them. You cannot access another apps views.

Only specific tasks can be performed in the background, see Background Execution .

You cannot guarantee that your app will remain in the background state - it may be terminated at any time by iOS.

From another angle: an app that did this would be using processor time and memory in a way the user may not expect even though they had dismissed it, which is not a well behaved app. When your app us dismissed by the user it needs to stop or at least minimise processor and memory usage and Apple and iOS will enforce this.

No, you cannot do this. And that's good.

If you could capture the touch inputs of other apps you could also capture keyboard presses, which means: private messages of other chat apps, password input, etc...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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