使用Swift记录应用在后台iOS中的滑动次数 [英] Record swipe amount when app is in the background iOS using Swift

查看:105
本文介绍了使用Swift记录应用在后台iOS中的滑动次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找解决方案,发现只有特定的应用程序才具有后台功能,即位置数据和播放音乐.假设我们拥有此权限,是否有任何方法可以记录所有其他应用程序和主屏幕等的划动金额?最终目标是(总共)记录用户使用Swift滚动的距离.

I have been looking around for a solution and found only specific apps have background capabilities i.e. 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. 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...

这篇关于使用Swift记录应用在后台iOS中的滑动次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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