Skip to content

Commit 5b71af9

Browse files
author
Amit Prabhu
committed
added beaconstac delegate callbacks in swift example app with notifications
1 parent 606c2fe commit 5b71af9

File tree

2 files changed

+65
-15
lines changed

2 files changed

+65
-15
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ DerivedData
1616
*.hmap
1717
*.ipa
1818
*.xcuserstate
19-
19+
.DS_Store
2020
# CocoaPods
2121
#
2222
# We recommend against adding the Pods directory to your .gitignore. However

Examples/SwiftExample/SwiftExample/ViewController.swift

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,88 @@
22
// ViewController.swift
33
// SwiftExample
44
//
5-
// Copyright © 2015 Mobstac Inc. All rights reserved.
5+
// Copyright © 2016 Mobstac Inc. All rights reserved.
66
//
77

88
import UIKit
99

1010
class ViewController: UIViewController, BeaconstacDelegate
1111
{
12-
12+
1313
override func viewDidLoad()
1414
{
1515
super.viewDidLoad()
1616

17-
var beaconstac = Beaconstac.sharedInstanceWithOrganizationId(1xx, developerToken: "1ccxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
18-
MSLogger.sharedInstance().loglevel = MSLogLevel.Verbose
17+
MSLogger.sharedInstance().loglevel = .Verbose
1918

19+
let beaconstac = Beaconstac.sharedInstanceWithOrganizationId(10, developerToken: "1ccxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
20+
beaconstac.allowRangingInBackground = true
2021
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])
2223
}
23-
24-
func beaconstac(beaconstac: Beaconstac!, rangedBeacons beaconsDictionary: [NSObject : AnyObject]!)
24+
25+
override func didReceiveMemoryWarning()
2526
{
26-
print("Beacons ranged" + beaconsDictionary.description)
27+
super.didReceiveMemoryWarning()
2728
}
2829

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)
3239
}
3340

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)")
3787
}
3888
}
3989

0 commit comments

Comments
 (0)