Mac OS X Lion 中始终禁用定位服务

Mac OS X Lion 中始终禁用定位服务

一个简单的定位服务程序在我的机器上运行良好,突然停止工作。在进一步探究问题后,我意识到某个进程已禁用定位服务系统偏好设置 » 安全和隐私 » 隐私

我检查了启用位置服务,但它再次被自动禁用。

经过一番研究,我发现这不仅仅是我的程序,甚至内置的系统功能也会因为这个问题而失败。系统偏好设置 » 日期和时间 » 时区无法获取当前位置。

每次我检查启用位置服务,我在控制台日志中看到以下错误:

16/10/12 11:23:15.636 AM [0x0-0x42042].com.apple.systempreferences: ERROR,Time,372059595.636,Function,"CLInternalSetLocationServicesEnabled",CLInternalSetLocationServicesEnabled failed
16/10/12 11:23:15.638 AM [0x0-0x42042].com.apple.systempreferences: STACK,Time,372059595.636,1   CoreLocation                        0x00007fff8f9957be CLInternalSetLocationServicesEnabled + 110

笔记:

  • WiFi 已开启
  • 我没有安装 iOS 模拟器
  • 我使用 Xcode 版本 4.5 (4G182)
  • 我使用 Boot Camp 并使我的 MacBook Pro 实现双启动(Mac OS X Lion 和 Windows 7)
  • 我只做 Mac 开发,不做 iOS 开发

答案1

#!/bin/sh
launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist

defaults write /System/Library/LaunchDaemons/com.apple.locationd Disabled -bool false 

then

launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist

exit 0

答案2

我在 OSX 10.11(El Capitan)中遇到了同样的问题。

我找到了这个帖子(https://jamfnation.jamfsoftware.com/discussion.html?id=5336#responseChild65097)。我运行了其中的脚本,最终我的定位服务得到了修复。

#!/bin/bash

########################## SET SYSTEM TIME  ##################################################
#
# Written by Tim Kimpton
#
# using information from https://jamfnation.jamfsoftware.com/discussion.html?id=5336
#
# If the machine is 5 minutes out of the kdc the machine will not bind to the domain.
#
# This script does the folling to ensure the time is correct
#
# 1. Unload the launch daemon used for location services
#
# 2. Get the hardware UUID of the machine and put it in the location services db
#
# 3. Enable location services
#
# 4. Correct permissions on the database file used for location services
#
# 5. Set the time zone to update the time automatically
#
# 6. Set the network time to on
#
# For information see https://jamfnation.jamfsoftware.com/discussion.html?id=5336
###############################################################################################

######################### ENVIRONMENT VARIABLES #######################

# Get the Hardware UUID from system profiler
uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)

####################### DO NOT MODIFY BELOW THIS LINE #################

# Unload the launch daemon
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist

# Write the UUID to the hidden plist file and initialise it
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd."$uuid" LocationServicesEnabled -int 1

# Enable Location Services
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.notbackedup."$uuid" LocationServicesEnabled -int 1

# Make sure the permissions on the database file is correct
/usr/sbin/chown -R _locationd:_locationd /var/db/locationd
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist

# Set time zone to update automatically
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool true

# Set network time to on
/usr/sbin/systemsetup -setusingnetworktime on > /dev/null 2>&1

exit 0

相关内容