【问题标题】:how to get UUID in swift didEnterRegion如何在 swift didEnterRegion 中获取 UUID
【发布时间】:2017-08-28 00:28:18
【问题描述】:
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
    print("didEnterRegion")


    let beaconRegion = region as! CLBeaconRegion

    let content = UNMutableNotificationContent()

    content.title = NSString.localizedUserNotificationString(forKey: "I came", arguments: nil)
    content.body = NSString.localizedUserNotificationString(forKey: "My Information:\(region.identifier), major:\(beaconRegion.major!)/minor:\(beaconRegion.minor!)", arguments: nil)
    content.sound = UNNotificationSound.default()
    content.badge = UIApplication.shared.applicationIconBadgeNumber as NSNumber?;
    content.categoryIdentifier = "com.elonchan.localNotification"
    // Deliver the notification in five seconds.
    let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 1, repeats: false)
    let request = UNNotificationRequest.init(identifier: region.identifier, content: content, trigger: trigger)

    // Schedule the notification.
    let center = UNUserNotificationCenter.current()
    center.add(request)
    userdefalut.set(nowTime, forKey: "lastDate_\(tempUUID_2)")
    userdefalut.synchronize()
    print(UIDevice.current.identifierForVendor!.uuidString)
}

CLBeaconRegion(proximityUUID: UUID(uuidString: "00000000-0000-0000-0000-(name)")!, major:208, minor:56, identifier: "(name)(path)")

如何在 didEnterRegion 中获取 UUID? 请帮帮我..

【问题讨论】:

    标签: swift xcode bluetooth bluetooth-lowenergy ibeacon


    【解决方案1】:

    您只需将CLRegion 转换为CLBeaconRegion。就像在 Swift 3 中这样:

    let beaconRegion = region as! CLBeaconRegion
    

    或者目标 C 中的这个:

    CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
    

    完成此操作后,您可以访问CLBeaconRegion 上的任何字段:

    斯威夫特 3:

    NSLog("My UUID: \(beaconRegion.proximityUUID)")
    

    目标 C:

    NSLog(@"My UUID: %@", beaconRegion.proximityUUID);
    

    【讨论】:

      【解决方案2】:

      你可以试试这个..

      func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
          manager.startRangingBeaconsInRegion((region as! CLBeaconRegion))
          var r = (region as! CLBeaconRegion)
          self.sendLocalNotificationWithMessage("\(r.proximityUUID)")
          self.sendLocalNotificationWithMessage("\(r.identifier)")
      }
      

      【讨论】:

        猜你喜欢
        • 2011-04-19
        • 1970-01-01
        • 2022-01-11
        • 2016-02-28
        • 1970-01-01
        • 2017-08-10
        • 2014-12-08
        • 1970-01-01
        • 2015-02-12
        相关资源
        最近更新 更多