CMMotionActivityManager
님의 startActivityUpdatesToQueue
을 백그라운드에서 사용하려고합니다.코어 모션은 인증/.plist 정보가 필요합니까?
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
파일이 있습니까?
감사합니다!
이 답변을보십시오, 그는 백그라운드에서 활동을 얻을 수 있다고 말했습니다 : http://stackoverflow.com/questions/40238591/is-it-possible-to-detect-the-users-moving-activity-on - 배경/40239325 # 40239325 잘못 됐니? –
그 대답은 기본적으로 내 것과 동일합니다. 앱을 실행시키기 위해 위치 업데이트와 같은 다른 백그라운드 모드를 사용해야합니다. 그런 다음이 백그라운드 실행을 활용하여 모션 활동 업데이트를 수신 할 수 있습니다. 자신의 활동 변경으로 앱이 정지 상태에서 백그라운드 실행 상태로 이동하지 않습니다. – Paulw11
아, 조금 설명해 드리겠습니다. 앱에서 일부 지역 모니터링이 있는데, 도착한 사용자에게 알림을 보내려고합니다. 일부 지역 (예 : "집")이 걷고있는 중이므로 'didEnterRegion' 메소드에 추가 한 코드를 호출하고 있습니다. 괜찮습니까? –