How to calculate current location in WatchKit extension

后端 未结 3 1664
天涯浪人
天涯浪人 2020-12-09 13:28

How to calculate the current user location in Watch Kit extension as we can\'t use CoreLocation in watch kit.

Thanks in advance

3条回答
  •  天命终不由人
    2020-12-09 13:43

    The answer by Stephan should work (haven't tested it), with just one exception. WatchKit requires "Always" permission for the location manages. This is because your phone is really running the watch extension, in background mode. So if you only ask for "When in Use" permission, you will never get locations returned to your watch extension.

    Try changing the line:

    if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse)
    

    with:

    if (status == kCLAuthorizationStatusAuthorizedAlways)
    

提交回复
热议问题