标签: core-motion

来自OpenGL的CMSampleBuffer用于AVAssestWritter的视频输出

我需要为OpenGL框架获取CMSampleBuffer.我正在使用这个:

int s = 1;
        UIScreen * screen = [UIScreen mainScreen];
        if ([screen respondsToSelector:@selector(scale)]){
            s = (int)[screen scale];
        }
        const int w = viewController.view.frame.size.width/2;
        const int h = viewController.view.frame.size.height/2;
        const NSInteger my_data_length = 4*w*h*s*s;
        // allocate array and read pixels into it.
        GLubyte * buffer = malloc(my_data_length);
        glReadPixels(0, 0, w*s, h*s, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
        // gl renders "upside down" so swap top to bottom into new array.
        GLubyte * buffer2 = malloc(my_data_length);
        for(int y = 0; y < h*s; y++){ …
Run Code Online (Sandbox Code Playgroud)

iphone opengl-es objective-c avassetwriter core-motion

5
推荐指数
1
解决办法
4816
查看次数

更新为deviceMotionUpdateInterval设置的频率是实际频率吗?

分析deviceMotion.timestamp我发现DeviceMotion中设置的更新频率不是实际的更新频率.

我实现了一个应用程序,以便测试,低于我所看到的!

    update frequency     actual frequency       average time between two calls
       1/10.000000          10.232265              0.097730
       1/20.000000          19.533729              0.051194
       1/30.000000          30.696613              0.032577
       1/40.000000          42.975122              0.023269
       1/50.000000          53.711000              0.018618
       1/60.000000          53.719106              0.018615
       1/70.000000          71.627016              0.013961
       1/80.000000          71.627263              0.013961
       1/90.000000          53.719365              0.018615
       1/100.000000        107.442667              0.009307
       1/110.000000        107.437022              0.009308
Run Code Online (Sandbox Code Playgroud)

有人注意到了同样的事情吗?这是一个错误吗?

iphone core-motion

5
推荐指数
1
解决办法
3780
查看次数

Core Motion的加速度计在后台模式下实现的奇怪行为

我在iOS上实现了一个计步器.一个重要的要求是,即使应用程序处于后台模式(例如,设备被锁定或用户按下主页按钮),它也必须工作.您可以在App Store中看到这样的实现,如Nike +,Runtastic Pedometer等.

一些SO帖子证实,这可以通过Core Motion实现,或者特别是CMMotionManager具有Required background modes设置为的附加属性location.

我使用下面的代码进行了快速测试,发现了一个奇怪的问题:

// AppDelegate.m
- (void)applicationDidEnterBackground:(UIApplication *)application
{ 
    if(self.motionManager==nil) {
        self.motionManager=[[CMMotionManager alloc] init];
    }
    self.motionManager.accelerometerUpdateInterval=1/50;

    if(self.accelerometerReadings==nil) 
        self.accelerometerReadings=[[NSMutableArray alloc] init];

    [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.accelerometerReadings addObject:accelerometerData];
        });
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    NSLog(@"The number of readings %d",self.accelerometerReadings.count);

    // do something with accelerometer data...
}
Run Code Online (Sandbox Code Playgroud)

我用iPhone 4S和iOS 6.1试过这段代码.当应用程序启动时,我按下主页按钮并摇动它(模拟行走)5秒钟,然后再次打开应用程序.这些动作重复了几次.我得到的输出是:

2013-02-05 16:41:42.028 [1147:907] readings 0
2013-02-05 16:41:51.572 [1147:907] readings 444
2013-02-05 16:42:00.386 [1147:907] readings …
Run Code Online (Sandbox Code Playgroud)

accelerometer background-process ios core-motion cmmotionmanager

5
推荐指数
1
解决办法
1532
查看次数

如何检测手机何时放下

我想在手机静止2秒钟后采取措施。我已经搜索了谷歌周围的年龄和堆栈溢出。我发现“ Accelerometer DidAccelerate”已贬值,而CoreMotion替代了它。我所看到的一切都与“摇动”动作有关。我已经尝试阅读苹果的文档,但这让我感到困惑!

基本上,我希望应用程序能够检测到手机上的重力在一定时间内保持在很小的范围内(建议您将手机放在桌子上或其他物体上)并进行呼叫和实例化或让应用执行某项操作。

任何帮助将不胜感激。

xcode objective-c accelerometer ios core-motion

5
推荐指数
1
解决办法
3312
查看次数

使用CoreMotion在后台获取加速度计数据

我无法在后台接收加速计数据,尽管每个问题看似正确的解决方案iPhone上的Nike + GPS如何在后台接收加速度计更新?

[_motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
                                         withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
                                             dispatch_async(dispatch_get_main_queue(), ^{
                                                 NSLog(@"perform");
                                                 [(id) self setAcceleration:accelerometerData.acceleration];
                                                 [self performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:NO];
                                             });}];
Run Code Online (Sandbox Code Playgroud)

当应用程序在前台时,会记录执行,但每当我退出到后台时,它都会停止运行.有谁知道为什么会这样?我在后台模式中检查了"位置更新"...

objective-c ios core-motion

5
推荐指数
1
解决办法
3096
查看次数

CMAccelerometerData和CMDeviceMotion之间的区别

有人可以解释之间的差异CMAccelerometerDataCMDeviceMotion.

在我看来,加速度值CMAccelerometerData是原始值,因为数据以CMDeviceMotion某种方式插值,或类似的东西.

accelerometer ios core-motion

5
推荐指数
2
解决办法
2514
查看次数

CMPedometer StepCounting不可用

我的代码是:

if ([CMPedometer isStepCountingAvailable]) {

        self.pedometer = [[CMPedometer alloc] init];
    }
    else {
        NSLog(@"Step counting is not available on this device!");
        [SVProgressHUD showErrorWithStatus:@"Step counting is not available on this device!"];
    }
Run Code Online (Sandbox Code Playgroud)

当我在iOS8及更高版本的设备上运行它时,它说:

此设备无法进行步数计数!

我怎样才能将其用于计步?

iphone objective-c ios core-motion

5
推荐指数
1
解决办法
1745
查看次数

SceneKit和CoreMotion在iPhone 5上"落后",但在iPhone 6上正常

我正在使用SceneKit测试,所以我决定制作一个虚拟现实测试应用程序.我将从设备运动中获取数据,然后根据数据更改摄像机角度.我在iPhone 6上测试,所以没问题.当我在iPhone 5和朋友的iPhone 5S上运行它时,事情变得奇怪,相机将需要一些延迟旋转,与iPhone 6上的瞬间完全不同.Xcode上的FPS在两个设备上保持大约60 FPS,我添加了一些时间测试,并且两个设备上的运动数据也在60Hz左右.我迷路了.

代码的基础是这个项目:https://github.com/stevenjs/VR-iOS-Experiment

如果可能的话,我想了解一些如何修复它的提示,而不仅仅是准备复制和粘贴的代码.我想学.

我无法用文字解释,所以我录制了一些视频来告诉你发生了什么:

iPhone 6:https://www.youtube.com/watch?v = pdyTEwvsR1I

iPhone 5:https://www.youtube.com/watch?v = Dr.DdKtHkrYo

这是代码:

    // Create Scene
    var scene = SCNScene()
    scnView.scene = scene
    //scnView.autoenablesDefaultLighting = true

    //Add camera to scene.
    let camera = SCNCamera()
    camera.xFov = 45
    camera.yFov = 45

    let camerasNode = SCNNode()
    camerasNode.camera = camera
    camerasNode.position = SCNVector3(x: 0, y: 0, z: 0)
    // The user will be holding their device up (i.e. 90 …
Run Code Online (Sandbox Code Playgroud)

ios core-motion scenekit swift

5
推荐指数
1
解决办法
1345
查看次数

Swift CoreMotion在后台检测设备上的Tap或Knock

我目前正在构建我的第一个iOS Swift应用程序,使用此应用程序我想在应用程序在后台运行时执行操作.

一旦用户在设备上点击两次,就需要执行该操作.

我启用了后台模式:应用功能中的位置更新

并在AppDelegate中设置AccelerometerUpdatesToQueue函数:

let manager = CMMotionManager()

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

if manager.accelerometerAvailable {
    manager.accelerometerUpdateInterval = 0.01
    manager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue()) {
        [weak self] (data: CMAccelerometerData!, error: NSError!) in

        println(data.acceleration.z)
    }
}

     return true
}
Run Code Online (Sandbox Code Playgroud)

控制台按预期打印出acceleration.z值,但是一旦按下主页按钮,控制台就会打印停止.

我在网上搜索了一个关于如何做到这一点的示例代码,我知道这是可能的...因为我们都知道应用程序"Knock Knock to unlock",但我似乎无法找到一段示例代码对斯威夫特来说.

ios core-motion swift

5
推荐指数
1
解决办法
3035
查看次数

CoreLocation:CPAS数据响应是invaild

在带有iOS 10.0.2的iPhone 6上,我收到以下代码的错误:

class ViewController: UIViewController {

    @IBOutlet weak var startStop: UIButton!

    var isRunning = false

    let manager: CMMotionManager = {
        let manager = CMMotionManager()
        manager.deviceMotionUpdateInterval = 1/100
        return manager
    }()

    @IBAction func handleStartStop(_ sender: AnyObject) {
        if isRunning {
            stopMotionUpdates()
            startStop.setTitle("Start", for: .normal)
        } else {
            startMotionUpdates()
            startStop.setTitle("Stop", for: .normal)
        }
        isRunning = !isRunning
    }

    func startMotionUpdates() {
        manager.startDeviceMotionUpdates(using: .xTrueNorthZVertical, to: .main) { (data, error) in
            print("Roll: \(data!.attitude.roll), Pitch: \(data!.attitude.pitch), Yaw: \(data!.attitude.yaw)")
        }
    }

    func stopMotionUpdates() {
        manager.stopDeviceMotionUpdates()
    } …
Run Code Online (Sandbox Code Playgroud)

ios core-motion swift

5
推荐指数
1
解决办法
938
查看次数