|
2 | 2 | // ViewController.swift |
3 | 3 | // SwiftExample |
4 | 4 | // |
5 | | -// Copyright © 2015 Mobstac Inc. All rights reserved. |
| 5 | +// Copyright © 2016 Mobstac Inc. All rights reserved. |
6 | 6 | // |
7 | 7 |
|
8 | 8 | import UIKit |
9 | 9 |
|
10 | 10 | class ViewController: UIViewController, BeaconstacDelegate |
11 | 11 | { |
12 | | - |
| 12 | + |
13 | 13 | override func viewDidLoad() |
14 | 14 | { |
15 | 15 | super.viewDidLoad() |
16 | 16 |
|
17 | | - var beaconstac = Beaconstac.sharedInstanceWithOrganizationId(1xx, developerToken: "1ccxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
18 | | - MSLogger.sharedInstance().loglevel = MSLogLevel.Verbose |
| 17 | + MSLogger.sharedInstance().loglevel = .Verbose |
19 | 18 |
|
| 19 | + let beaconstac = Beaconstac.sharedInstanceWithOrganizationId(10, developerToken: "1ccxxxxxxxxxxxxxxxxxxxxxxxxxxxx") |
| 20 | + beaconstac.allowRangingInBackground = true |
20 | 21 | beaconstac.delegate = self |
21 | | - beaconstac.startRangingBeaconsWithUUIDString("F94DBB23-2266-7822-3782-57BEAC0952AC", beaconIdentifier: "MobstacRegion", filterOptions: nil) |
| 22 | + beaconstac.startRangingBeaconsWithUUIDString("F94DBB23-2266-7822-3782-57BEAC0952AC", beaconIdentifier: "MobstacRegion", filterOptions: ["myBeacons":true]) |
22 | 23 | } |
23 | | - |
24 | | - func beaconstac(beaconstac: Beaconstac!, rangedBeacons beaconsDictionary: [NSObject : AnyObject]!) |
| 24 | + |
| 25 | + override func didReceiveMemoryWarning() |
25 | 26 | { |
26 | | - print("Beacons ranged" + beaconsDictionary.description) |
| 27 | + super.didReceiveMemoryWarning() |
27 | 28 | } |
28 | 29 |
|
29 | | - func beaconstac(beaconstac: Beaconstac!, campedOnBeacon beacon: MSBeacon!, amongstAvailableBeacons beaconsDictionary: [NSObject : AnyObject]!) |
30 | | - { |
31 | | - print("Camped On Beacon" + beacon.beaconKey) |
| 30 | + func triggerLocalNotificationWithMessage(message: String) { |
| 31 | + UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)) |
| 32 | + |
| 33 | + let notification = UILocalNotification() |
| 34 | + notification.fireDate = NSDate(timeIntervalSinceNow: 0.1) |
| 35 | + notification.alertBody = message |
| 36 | + notification.alertAction = "open" |
| 37 | + notification.soundName = UILocalNotificationDefaultSoundName |
| 38 | + UIApplication.sharedApplication().scheduleLocalNotification(notification) |
32 | 39 | } |
33 | 40 |
|
34 | | - override func didReceiveMemoryWarning() |
35 | | - { |
36 | | - super.didReceiveMemoryWarning() |
| 41 | + // MARK: Beaconstac Delegate |
| 42 | + func beaconstac(beaconstac: Beaconstac!, didEnterBeaconRegion region: CLBeaconRegion!) { |
| 43 | + print("Beacon region entered \(region.identifier)") |
| 44 | + |
| 45 | + triggerLocalNotificationWithMessage("Entered beacon region \(region.identifier)") |
| 46 | + } |
| 47 | + |
| 48 | + func beaconstac(beaconstac: Beaconstac!, didExitBeaconRegion region: CLBeaconRegion!) { |
| 49 | + print("Beacon region exited \(region.identifier)") |
| 50 | + |
| 51 | + triggerLocalNotificationWithMessage("Exited beacon region \(region.identifier)") |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + func beaconstac(beaconstac: Beaconstac!, rangedBeacons beaconsDictionary: [NSObject : AnyObject]!) { |
| 56 | + print("Ranged beacons \(beaconsDictionary)") |
| 57 | + } |
| 58 | + |
| 59 | + func beaconstac(beaconstac: Beaconstac!, campedOnBeacon beacon: MSBeacon!, amongstAvailableBeacons beaconsDictionary: [NSObject : AnyObject]!) { |
| 60 | + print("Camped on beacon \(beacon)") |
| 61 | + |
| 62 | + triggerLocalNotificationWithMessage("Beacon camped on \(beacon.beaconKey)") |
| 63 | + } |
| 64 | + |
| 65 | + func beaconstac(beaconstac: Beaconstac!, exitedBeacon beacon: MSBeacon!) { |
| 66 | + print("Exited beacon \(beacon)") |
| 67 | + } |
| 68 | + |
| 69 | + func beaconstac(beaconstac: Beaconstac!, triggeredRuleWithRuleName ruleName: String!, actionArray: [AnyObject]!) { |
| 70 | + print("Triggered rule \(ruleName) with actions \(actionArray)") |
| 71 | + } |
| 72 | + |
| 73 | + func beaconstac(beaconstac: Beaconstac!, didEnterGeofenceRegion region: CLRegion!) { |
| 74 | + print("Entered geofence region \(region.identifier)") |
| 75 | + } |
| 76 | + |
| 77 | + func beaconstac(beaconstac: Beaconstac!, didExitGeofenceRegion region: CLRegion!) { |
| 78 | + print("Exited geofence region \(region.identifier)") |
| 79 | + } |
| 80 | + |
| 81 | + func beaconstac(beaconstac: Beaconstac!, didSyncRules ruleDict: [NSObject : AnyObject]!, withError error: NSError!) { |
| 82 | + print("Rules synced \(ruleDict)") |
| 83 | + } |
| 84 | + |
| 85 | + func beaconstac(beaconstac: Beaconstac!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) { |
| 86 | + print("User Location updated from \(oldLocation) to \(newLocation)") |
37 | 87 | } |
38 | 88 | } |
39 | 89 |
|
0 commit comments