2017-07-28 22 views
0

iBeaconが利用可能かどうかをアプリが検出できるかどうかを確認するために考えられる最も基本的なSwift 3コードである以下のコードを書きました。 しかし、didEnterRegionは青い月に1回だけ起動されます。私はたぶん私の電話で20回走ったんだけど、2回しか発砲しなかった。この問題は、私がApp Storeからアプリを使用するとき、いつも私のiBeaconを検出するように、ビーコン自体ではないようです。このコールバックがめったに呼び出されない理由は何ですか? PS:私はすでに追加されている個人情報保護 - ロケーション必ず使用方法の説明あなたは、地域の終了30秒ほど待って、それが引き金持って再び入力する必要がdidEnterRegionが時々だけ起動する

import UIKit 
import CoreLocation 

class ViewController: UIViewController { 

let locationManager = CLLocationManager() 

@IBOutlet weak var textLabel: UILabel! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    locationManager.requestAlwaysAuthorization() 
    locationManager.delegate = self 
    // Do any additional setup after loading the view, typically from a nib. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

@IBAction func startMonitoring(_ sender: Any) { 
    if let uuid = UUID(uuidString: "10F86430-1346-11E4-9191-0800200C9A66") { 
     let beaconRegion = CLBeaconRegion(proximityUUID: uuid, major: 1, minor: 1,identifier: "iBeacon") 
     locationManager.startMonitoring(for: beaconRegion) 
     textLabel.text = "Monitoring" 
    } 
} 
} 

extension ViewController: CLLocationManagerDelegate { 
func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) { 
    textLabel.text = "\(error.localizedDescription)" 
} 

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { 
    textLabel.text = "\(error.localizedDescription)" 
} 

func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) { 
     textLabel.text = "Found a new beacon" 
} 
} 

答えて

1

のInfo.plistします。あなたがその地域に滞在しているなら、それは誘発しません。

+0

これが最も可能性の高い説明です。 – davidgyoung