Reputation: 13
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)")
How Can I get UUID in didEnterRegion? Please Help me..
Upvotes: 1
Views: 1085
Reputation: 64941
You simply need to cast CLRegion
to CLBeaconRegion
. Like this in Swift 3:
let beaconRegion = region as! CLBeaconRegion
Or this in Objective C:
CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
Once you do that, you can access any fields on CLBeaconRegion
:
Swift 3:
NSLog("My UUID: \(beaconRegion.proximityUUID)")
Objective C:
NSLog(@"My UUID: %@", beaconRegion.proximityUUID);
Upvotes: 1
Reputation: 1287
You can try this..
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)")
}
Upvotes: 0