Senselytics Event Broadcasts
Error broadcasts
Senselytics framework provides a mechanism to listen to errors posted by the framework. All errors are posted as local notifications to the host app. Add observers for the notification named "C360DidFailWithErrorNotification" . Example usage shown below
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(errorOccured:)
name: C360DidFailWithErrorNotification
object: nil];
NotificationCenter.default.addObserver(self, selector: #selector(self.errorOccured), name: C360DidFailWithErrorNotification, object: nil)
The notification object carries the NSError object from where host app can identify the type of error encountered by the framework.
Rule broadcasts
Senselytics broadcasts a NSNotification when a rule starts executing or when it ends execution. Applications can listen to these broadcasts by adding a listener in the Application delegate file. Follow the steps below
Implement this function in your app delegate
Although you can listen to the rule broadcast messages in any class, it is highly encouraged to place a handler in your application delegate file. This is because a rule can execute when you app is the background and application delegate is guaranteed to not miss this event.
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(ruleExecuted:)
name: C360DidExecuteRuleNotification
object: nil];
NotificationCenter.default.addObserver(self, selector: #selector(self.ruleExecuted), name: C360DidExecuteRuleNotification, object: nil)
Then implement the function ruleExecuted:
- (void) ruleExecuted:(NSNotification *) notification
{
C360RuleExecutionRecord *ruleExecutionRecord = notification.object;
NSLog(@"******** Rule executed %@", ruleExecutionRecord);
}
func ruleExecuted(_ notification: Notification) {
let ruleExecutionRecord: C360RuleExecutionRecord? = notification.object
print("******** Rule executed \(ruleExecutionRecord)")
}
Contextual change broadcasts
Senselytics broadcasts a NSNotification when a change in user's location or motion is detected. Applications can listen to these broadcasts by adding a listener in the Application delegate file. Follow the steps below
Implement this function in your app delegate
Although you can listen to the rule broadcast messages in any class, it is highly encouraged to place a handler in your application delegate file. This is because a rule can execute when you app is the background and application delegate is guaranteed to not miss this event.
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(contextChanged:)
name: C360DidChangeContextNotification
object: nil];
NotificationCenter.default.addObserver(self, selector: #selector(self.contextChanged), name: C360DidChangeContextNotification, object: nil)
Then implement the function contextChanged:
- (void) contextChanged:(NSNotification *) notification
{
C360Context *context = notification.object;
if ([context isKindOfClass:[C360MotionContext class]])
{
// Motion context changed !
C360MotionContext *motionCtx = (C360MotionContext *) context;
NSLog(@"Motion changed to %@", motionCtx.estimatedActivityString);
}
else if ([context isKindOfClass:[C360LocationContext class]])
{
// Location context changed !
C360LocationContext *locationCtx = (C360LocationContext *) context;
NSLog(@"Location changed to %@ category %@", locationCtx.name, locationCtx.category);
}
else if ([context isKindOfClass:[C360SmartActivityContext class]])
{
C360SmartActivityContext *ctx = (C360SmartActivityContext *) context;
}
}
func contextChanged(_ notification: Notification) {
let context: C360Context? = notification.object
if (context? is C360MotionContext) {
// Motion context changed !
let motionCtx: C360MotionContext? = (context as? C360MotionContext)
print("Motion changed to \(motionCtx?.estimatedActivityString)")
}
else if (context? is C360LocationContext) {
// Location context changed !
let locationCtx: C360LocationContext? = (context as? C360LocationContext)
print("Location changed to \(locationCtx?.name) category \(locationCtx?.category)")
}
else if (context? is C360SmartActivityContext) {
// Location context changed !
let smartActivityCtx: C360SmartActivityContext? = (context as? C360SmartActivityContext)
}
}
Updated over 7 years ago