【问题标题】:Detect if GPS is activated in titanium studio检测钛工作室中是否激活了 GPS
【发布时间】:2026-02-11 12:00:02
【问题描述】:

如何检测 GPS 是否在 Android 和 IOS 中激活?

if (Ti.Geolocation.locationServicesEnabled == false) 
{

}

我已经尝试过了,但在 Android 上总是返回 tru,而在 IOS 上它似乎什么都不做。

我如何在钛金属中检测 android 和 IOS 的 GPS 状态?

【问题讨论】:

    标签: android ios gps geolocation titanium


    【解决方案1】:

    在 iOS GPS 中,应用程序启动时会询问用户的权限。您可以添加以下代码 ti.xml 并在 iOS 中为您启用 GPS,直到用户从设置中明确禁用此权限。 这是要添加到 ti.xml 中的代码

     <ti:app>
        <ios>
            <plist>
                <dict>
                    <key>NSLocationAlwaysUsageDescription</key>
                    <string>
                        Specify the reason for accessing the user's location information.
                        This appears in the alert dialog when asking the user for permission to
                        access their location.
                    </string>
                </dict>
            </plist>
        </ios>
    </ti:app>
    

    【讨论】: