Unity LocationServices无法在iOS上运行

时间:2017-02-21 21:59:00

标签: c# ios unity3d location-services

我有一个Unity 5.5.1f1项目,我尝试使用LocaitonServices来获取用户当前的GPS位置。我正在物理android和iOS设备上测试这个脚本。 LocationServices在Android上运行项目时会返回一个位置,但在iOS 10.2.1上它永远不会返回一个位置。是否有任何特定需要启用才能在iOS上使用设备位置?我使用Location Service Docs中的TestLocationService脚本:

using UnityEngine;
using System.Collections;

public class TestLocationService : MonoBehaviour
{
    IEnumerator Start()
    {
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
            yield break;

        // Start service before querying location
        Input.location.Start();

        // Wait until service initializes
        int maxWait = 20;
        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return new WaitForSeconds(1);
            maxWait--;
        }

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            print("Timed out");
            yield break;
        }

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            print("Unable to determine device location");
            yield break;
        }
        else
        {
            // Access granted and location value could be retrieved
            print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
        }

        // Stop service if there is no need to query location updates continuously
        Input.location.Stop();
    }
}

这是说Input.location.isEnabledByUser == false但我的设备上启用了位置服务。请注意,在打开应用程序时,我的iOS设备上从未提示我允许使用位置,但我在Android上。

0 个答案:

没有答案