首页 > 解决方案 > 为什么自 iOS 13 发布以来 iBeacon 没有触发进入和退出事件

问题描述

在最新的 iOS 13 版本中,Core Location 和 Core Bluetooth 框架有 2 个主要更新。用户有关于应用程序权限的更新。

以下链接解释了更新: https ://developer.apple.com/documentation/corelocation/getting_the_user_s_location/handling_location_events_in_the_background

https://medium.com/@arora.malika9/whats-new-in-core-location-in-ios-13-1275351686bd

https://medium.com/q42-engineering/apple-location-permission-ios13-1e0e59002889

https://gimbal.com/ios-13-location-permissions/

https://blog.estimote.com/post/186160021855/get-ready-for-ios-13-bluetooth-and-location

在以下 3 种方法中,iBeacon 触发器根据应用程序的状态在应用程序中交付:

  1. 当应用程序处于前台/后台状态时:

    func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {

    }

    func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {

    }

  2. 当应用程序从终止/暂停状态唤醒时:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let dataForLocation = launchOptions? [UIApplication.LaunchOptionsKey.location] 作为?[字符串:任何] if dataForLocation != nil {

           }
    

    }

项目设置如下:

  1. 目标 -> 签名和功能 -> 后台模式 -> 位置更新、后台获取和远程通知已启用
  2. 在 Info.plist 中存在以下内容:

    
<key>NSBluetoothAlwaysUsageDescription</key>
    <string>$(PRODUCT_NAME) uses bluetooth</string>
    
    <key>NSBluetoothPeripheralUsageDescription</key>
    <string>$(PRODUCT_NAME) uses peripheral</string>
    
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>$(PRODUCT_NAME) uses location services</string>
    
    <key>NSLocationAlwaysUsageDescription</key>
    <string>$(PRODUCT_NAME) uses location services</string>
    
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>$(PRODUCT_NAME) uses location services</string> 
    
    <key>allowsBackgroundLocationUpdates</key>
    <true/>
    
    <key>UIBackgroundModes</key>
    <array>
    	<string>bluetooth-central</string>
    	<string>fetch</string>
    	<string>location</string>
    	<string>remote-notification</string>
    </array>

我是否缺少 iOS 13 所需的任何其他支持?有随机事件生成且没有稳定性。

标签: iosswiftibeaconios13

解决方案


推荐阅读