2017-04-03 47 views
1
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-(名)」)!專業:​​208,次要:56,標識符:「(名)(路徑)「)如何獲得UUID在迅速didEnterRegion

如何在didEnterRegion中獲得UUID? 請幫助我..

回答

0

你可以試試這個..

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)") 
} 
0

您只需投CLRegionCLBeaconRegion。像這樣的斯威夫特3:

let beaconRegion = region as! CLBeaconRegion 

或者,這在Objective C:

CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region; 

一旦你這樣做,你可以訪問CLBeaconRegion任何字段:

斯威夫特3:

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

Objective C:

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