User Trigger
Magnet Max offers user trigger capability. Users can define customized rules with actions (e.g., send a message to a specific user) that can be triggered if the time AND/OR location condition is satisfied.
By using the User Trigger function, it's easy to achieve the following use cases.
Case 1. A user wants to send a message to anyone in a target group:
- if target group user(s) are in a specific location AND/OR
- during a certain timeframe
Case 2. A user wants to get push notifications from anyone in the target group:
- if the user is in a specific location AND/OR
- during a certain timeframe
The Magnet Max SDK provides the following APIs to handle the user trigger function.
Create New User Rule
The following creates a new user rule.
let ruleCond = MMUserRuleCondition(type:MMUserRuleConditionType.TIME_AND_LOCATION, timeBegin: Date(timeIntervalSinceNow:28800), locLatitude:37.4518, locLongitude:-122.1151, locCheckUsersId:["uid_01", "uid_02"])
let ruleAction = MMUserRuleAction(targetUsersId:["uid_03"], msgTitle:"VIP", msgBody:"VIP is here")
let userRule = MMUserRule(name:"new rule", condition:ruleCond, actions:[ruleAction])
MMUserRule.createUserRule(userRule, success: {(newRule) in
//Success
}, failure: { (error) in
//Failure
})
Update Existing User Rule
The following updates an existing user rule.
userRule.active = false
MMUserRule.updateUserRule(userRule, success: {(updatedRule) in
//Success
}, failure: { (error) in
//Failure
})
Delete User Rule
The following deletes an existing user rule.
MMUserRule.deleteUserRule(userRuleId, success: {() in
//Success
}, failure: { (error) in
//Failure
})
Fetch User Rules
You can retrieve user rules by user or by rule ID.
The following will fetch all existing rules created by the current user.
MMUserRule.getAllMyRules(success: {(allRules) in
//Success
}, failure: { (error) in
//Failure
})
The following will fetch a user rule with a specific ID.
MMUserRule.getRuleWithID(userRuleId, success: {(userRule) in
//Success
}, failure: { (error) in
//Failure
})
Trigger Rule Actions
The following notifies the server that the rule actions should be triggered (e.g., user location condition in the rule is satisfied).
UserRule.trigger(success: {() in
//Success
}, failure: { (error) in
//Failure
})