The FMPPush class is used to work with push notifications.
class FMPPush
Property | Description |
service |
Push notifications service. var service: FMPPush.Service { get } |
token |
The current device token. var token: String { get } |
Method | Description |
tokens(completion:) |
Get list of device tokens for the current user. func tokens(completion: @escaping FMPTokensHandler) Parameters:
|
topics(completion:) | Get list of message topics available for the current user. func topics(completion: @escaping FMPTopicsHandler) Parameters:
|
addToken(completion:) | Add the current device token to the list of token available for the user on server. func addToken(completion: @escaping FMPRequestResponseHandler) Parameters:
|
removeToken(completion:) | Delete the current device token from the list of tokens available for the user on server. func removeToken(completion: @escaping FMPRequestResponseHandler) Parameters:
|
subscribe(to:completion:) | Subscribe to messages with the specified topics. func subscribe(to topics: [String], completion: @escaping FMPRequestResponseHandler) Parameters:
|
unsubscribe(from:completion:) | Unsubscribe from messages with the specified topics. func unsubscribe(from topics: [String], completion: @escaping FMPRequestResponseHandler) Parameters:
|
copy() | Get instance of builder class for copying FMPPush. It returns the instance of the FMPPush.Builder builder class. func copy() -> FMPPush.Builder |
Get list of device tokens:
// Build an instance of the FMPPush class. For details see examples for FMPPush.Builder.
let push: FMPPush = fmp.push.build()
// Get list of tokens
push.tokens { (success, error, tokens) in
if success {
// Display token identifiers
print(tokens.map {$0.token})
} else {
// Display error code and description
print(error?.code, error?.description)
}
}
Get list of message topics:
// Build an instance of the FMPPush class. For details see examples for FMPPush.Builder.
let push: FMPPush = fmp.push.build()
// Get list of message topics
push.topics { (success, error, topics) in
if success {
// Display topic names
print(topics.map {$0.name})
} else {
// Display error code and description
print(error?.code, error?.description)
}
}
Add/delete the current device token on server:
// Build an instance of the FMPPush class. For details see examples for FMPPush.Builder.
let push: FMPPush = fmp.push.build()
// Add a device token to server
push.addToken { (response) in
if response.success {
// Display server response
print(response.result)
} else {
// Display error code and description
print(response.error?.code, response.error?.description)
}
}
// Delete device token from server
push.removeToken { (response) in
if response.success {
// Display server response
print(response.result)
} else {
// Display error code and description
print(response.error?.code, response.error?.description)
}
}
Subscribe/unsubscribe from message topics:
// Build an instance of the FMPPush class. For details see examples for FMPPush.Builder.
let push: FMPPush = fmp.push.build()
// Subscribe to several message topics
push.subscribe(to: ["topic1","topic2"]) { (response) in
if response.success {
// Display server response
print(response.result)
} else {
// Display error code and description
print(response.error?.code, response.error?.description)
}
}
// Unsubscribe from several message topics
push.unsubscribe(from: ["topic1","topic2"]) { (response) in
if response.success {
// Display server response
print(response.result)
} else {
// Display error code and description
print(response.error?.code, response.error?.description)
}
}
Copy FMPPush:
// Build an instance of the FMPPush class. For details see examples for FMPPush.Builder.
let push: FMPPush = fmp.push.build()
// Copy instance of the FMPPush class.
let pushCopy: FMPPush = push.copy().build()
See also: