gpt4 book ai didi

ios - Core Motion 是否需要授权/.plist 信息?

转载 作者:行者123 更新时间:2023-11-30 12:57:11 26 4
gpt4 key购买 nike

我正在尝试在后台使用 CMMotionActivityManagerstartActivityUpdatesToQueue

但它似乎不起作用,除了添加此代码之外,我还需要做其他事情吗:

        if CMMotionActivityManager.isActivityAvailable() {
CMMotionActivityManager().startActivityUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: { (activity: CMMotionActivity?) in
if (activity?.automotive)! {
let notification = UILocalNotification()
notification.alertTitle = "Arounder"
notification.alertBody = "User using car"
notification.soundName = "Notification Sound"
notification.category = "category"

UIApplication.sharedApplication().scheduleLocalNotification(notification)

print(notification.alertBody)
} else if (activity?.cycling)! {
let notification = UILocalNotification()
notification.alertTitle = "Arounder"
notification.alertBody = "User is cycling"
notification.soundName = "Notification Sound"
notification.category = "category"

UIApplication.sharedApplication().scheduleLocalNotification(notification)
print(notification.alertBody)
} else if (activity?.walking)! || (activity?.running)! {
let notification = UILocalNotification()
notification.alertTitle = "Arounder"
notification.alertBody = "User is walking/running"
notification.soundName = "Notification Sound"
notification.category = "category"

UIApplication.sharedApplication().scheduleLocalNotification(notification)
print(notification.alertBody)
} else if (activity?.stationary)! {
let notification = UILocalNotification()
notification.alertTitle = "Arounder"
notification.alertBody = "User is standing"
notification.soundName = "Notification Sound"
notification.category = "category"

UIApplication.sharedApplication().scheduleLocalNotification(notification)
print(notification.alertBody)
} else if (activity?.unknown)! {
let notification = UILocalNotification()
notification.alertTitle = "Arounder"
notification.alertBody = "Unknown activity"
notification.soundName = "Notification Sound"
notification.category = "category"

UIApplication.sharedApplication().scheduleLocalNotification(notification)
print(notification.alertBody)
}
})
}

我是否需要像 Core Location (requestAlwaysAuthorization) 中那样获得用户的许可? .plist 文件是什么?

谢谢!

最佳答案

当您的应用处于后台(挂起)时,

CMMotionActivityManager 不会提供更新。来自 documentation :

The handler block is executed on a best effort basis and updates are not delivered while your app is suspended. If updates arrived while your app was suspended, the last update is delivered to your app when it resumes execution. To get all of the updates that occurred while your app was suspended, use the queryActivityStarting(from:to:to:withHandler:) method.

您可以使用其他一些后台模式(例如显着位置更改模式)让您的应用定期恢复后台执行并借此机会检索事件更新,但运动类型本身会发生变化 不会导致您的应用程序从挂起执行到后台执行。

关于ios - Core Motion 是否需要授权/.plist 信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40292424/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com