The account, tag, and user attribute features in this document are applicable to SDK v1.2.9.0 and later. For SDK v1.2.7.2 and earlier, see API Documentation.
The following are device registration API methods. For more information on the timing and principle of calls, see Device registration flow.
This API is used to launch the Tencent Push Notification Service by using the information of the application registered at the official website of Tencent Push Notification Service.
(This API is newly added in SDK v1.2.7.2. For v1.2.7.1 and earlier, see the startXGWithAppID
API in the XGPush.h
file in the SDK package.)
/// @note Tencent Push Notification Service SDK v1.2.7.2 or later
- (void)startXGWithAccessID:(uint32_t)accessID accessKey:(nonnull NSString *)accessKey delegate:(nullable id<XGPushDelegate>)delegate;
accessID
: AccessID
applied through the frontendaccessKey
: AccessKey
applied through the frontendDelegate
: callback object Note:The parameters required by the API must be entered correctly; otherwise, Tencent Push Notification Service will not be able to push messages correctly for the application.
[[XGPush defaultManager] startXGWithAccessID:<your AccessID> accessKey:<your AccessKey> delegate:self];
The following are device unregistration API methods. For more information on the timing and principle of calls, see Device unregistration flow.
After the Tencent Push Notification Service is stopped, the application will not be able to push messages to devices through it. To receive messages pushed by it again, you must call the startXGWithAccessID:accessKey:delegate:
method again to re-activate the service.
- (void)stopXGNotification;
[[XGPush defaultManager] stopXGNotification];
This API is used to query the token string generated by the current application on the Tencent Push Notification Service server.
@property (copy, nonatomic, nullable, readonly) NSString *xgTokenString;
NSString *token = [[XGPushTokenManager defaultTokenManager] xgTokenString];
Note:Token query should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
After the SDK is started, use this method callback to return the registration result and token.
- (void)xgPushDidRegisteredDeviceToken:(nullable NSString *)deviceToken xgToken:(nullable NSString *)xgToken error:(nullable NSError *)error
deviceToken
: device token generated by APNs.xgToken
: token generated by Tencent Push Notification Service, which needs to be used during message push. Tencent Push Notification Service maintains the mapping relationship between this value and the device token generated by APNs.error
: error message. If error
is nil
, Tencent Push Notification Service has been successfully registered.This callback is new in SDK v1.2.7.2 and used for Tencent Push Notification Service registration failures.
/// @note Tencent Push Notification Service SDK v1.2.7.2 or later
- (void)xgPushDidFailToRegisterDeviceTokenWithError:(nullable NSError *)error
This API was added in SDK v1.3.1.0 and is used to call back the result of notification authorization pop-up window.
- (void)xgPushDidRequestNotificationPermission:(bool)isEnable error:(nullable NSError *)error;
isEnable
: whether authorization is approved or not.error
: error message. If error
is nil
, the pop-up authorization result has been successfully obtained.The following are account API methods. For more information on the timing and principle of calls, see Account flow.
If there is no account of this type, this API will add a new one; otherwise, it will overwrite the existing one. (This API is available only in Tencent Push Notification Service SDK v1.2.9.0 or later.)
- (void)upsertAccountsByDict:(nonnull NSDictionary<NSNumber *, NSString *> *)accountsDict;
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
accountsDict
: account dictionary
Note:
- The account type and account name together serve as the composite primary key.
- You need to use the dictionary type, where
key
is the account type andvalue
is the account, for example, @{@(accountType):@"account"}.- Syntax for Objective-C: @{@(0):@"account0",@(1):@"account1"}; syntax for Swift:[NSNumber(0):@"account0",NSNumber(1):@"account1"]
- For more
accountType
values, see theXGPushTokenAccountType
enumeration in the SDK demo package or Account Type Value Table.
XGPushTokenAccountType accountType = XGPushTokenAccountTypeUNKNOWN;
NSString *account = @"account";
[[XGPushTokenManager defaultTokenManager] upsertAccountsByDict:@{ @(accountType):account }];
This API is used to add or update a mobile number. It is equivalent to calling upsertAccountsByDict:@{@(1002):@"specific mobile number"}
.
/// @note Tencent Push Notification Service SDK v1.3.2.0+
- (void)upsertPhoneNumber:(nonnull NSString *)phoneNumber;
phoneNumber
: an E.164 mobile number in the format of [+][country code or area code][mobile number]
, for example, +8613711112222. The SDK will encrypt the mobile number for transmission.[[XGPushTokenManager defaultTokenManager] upsertPhoneNumber:@"+8613712345678"];;
Note:1. This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
2. You can calldelAccountsByKeys:[[NSSet alloc] initWithObjects:@(1002), nil]
to delete a mobile number.
This API is used to delete all accounts of a specified account type. (This API is available only in Tencent Push Notification Service SDK v1.2.9.0 or later.)
- (void)delAccountsByKeys:(nonnull NSSet<NSNumber *> *)accountsKeys;
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
accountsKeys
: set of account typesNote:
- A set is required, and the key is fixed.
- For more values of
accountType
, see the enumerated values ofXGPushTokenAccountType
in theXGPush.h
file in the SDK package.
XGPushTokenAccountType accountType = XGPushTokenAccountTypeUNKNOWN;
NSSet *accountsKeys = [[NSSet alloc] initWithObjects:@(accountType), nil];
[[XGPushTokenManager defaultTokenManager] delAccountsByKeys:accountsKeys];
This API is used to clear all set accounts.
- (void)clearAccounts;
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
[[XGPushTokenManager defaultTokenManager] clearAccounts];
The following are tag API methods. For more information on the timing and principle of calls, see Tag flow.
This API is used to bind tags to different users so that push can be performed based on specific tags.
- (void)appendTags:(nonnull NSArray<NSString *> *)tags
- (void)delTags:(nonnull NSArray<NSString *> *)tags
Note:
- This API works in an appending manner.
- This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.- One application can have up to 10,000 custom tags. One device token can be bound to a maximum of 100 custom tags (to increase this limit, submit a ticket). One custom tag can be bound to an unlimited number of device tokens.
tags
: tag array
Note:For tag operations,
tags
is a tag string array, which cannot contain spaces or tabs.
// Bind tags
[[XGPushTokenManager defaultTokenManager] appendTags:@[ tagStr ]];
// Unbind tags
[[XGPushTokenManager defaultTokenManager] delTags:@[ tagStr ]];
This API is used to clear all the existing tags and then add tags in batches.
- (void)clearAndAppendTags:(nonnull NSArray<NSString *> *)tags
Note:
- This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.- This API will replace all the old tags corresponding to the current token with the current tag.
tags
: tag array
Note:For tag operations,
tags
is a tag string array, which cannot contain spaces or tabs.
[[XGPushTokenManager defaultTokenManager] clearAndAppendTags:@[ tagStr ]];
This API is used to clear all set tags.
- (void)clearTags
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
[[XGPushTokenManager defaultTokenManager] clearTags];
This API is new in SDK v1.3.1.0 and used to query the tags bound to the device.
- (void)queryTags:(NSUInteger)offset limit:(NSUInteger)limit;
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
offset
: the offset of this querylimit
: the page size for this query; maximum value: 200
[[XGPushTokenManager defaultTokenManager] queryTags:0 limit:100];
This API is new in SDK v1.3.1.0 and used to call back the result of tag query.
- (void)xgPushDidQueryTags:(nullable NSArray<NSString *> *)tags totalCount:(NSUInteger)totalCount error:(nullable NSError *)error;
tags
: tags returned for the querytotalCount
: total number of the tags bound to the deviceerror
: error message. If error
is nil
, the query is successful.The following are user attribute API methods. For more information on the timing and principle of calls, see User attribute flow.
This API is used to add or update user attributes in the key-value
structure (if there is no user attribute value corresponding to the key, it will add a new one; otherwise, it will update the value).
- (void)upsertAttributes:(nonnull NSDictionary<NSString *,NSString *> *)attributes
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
attributes
: dictionary of user attribute strings, which cannot contain spaces or tabs
Note:
- You need to configure user attribute keys in the console first before the operation can succeed.
- Both
key
andvalue
can contain up to 50 characters.- A dictionary is required, and
key
is fixed.- Syntax for Objective-C: @{@"gender": @"Female", @"age": @"29"}
- Syntax for Swift: ["gender":"Female", "age": "29"]
[[XGPushTokenManager defaultTokenManager] upsertAttributes:attributes];
The API is used to delete existing user attributes.
- (void)delAttributes:(nonnull NSSet<NSString *> *)attributeKeys
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
attributeKeys
: set of user attribute keys, which cannot contain spaces or tabs
Note:It is required to use a key set.
[[XGPushTokenManager defaultTokenManager] delAttributes:attributeKeys];
This API is used to clear all existing user attributes.
- (void)clearAttributes;
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
[[XGPushTokenManager defaultTokenManager] clearAttributes];
This API is used to clear all the existing user attributes and then add user attributes in batches.
- (void)clearAndAppendAttributes:(nonnull NSDictionary<NSString *,NSString *> *)attributes
Note:This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.
[[XGPushTokenManager defaultTokenManager] clearAndAppendAttributes:attributes];
This API is used to sync the modified local badge value of an application to the Tencent Push Notification Service server for the next push. You can choose Create Push > Advanced Settings > Badge Number in the console to configure the badge number.
- (void)setBadge:(NSInteger)badgeNumber;
badgeNumber
: badge number of an application
Note:When the local badge number is set for the application, you need to call this API to sync it to the Tencent Push Notification Service server, which will take effect in the next push. This API must be called after the Tencent Push Notification Service persistent connection is established successfully (xgPushNetworkConnected).
/// Timing for calling a cold start
- (void)xgPushDidRegisteredDeviceToken:(nullable NSString *)deviceToken xgToken:(nullable NSString *)xgToken error:(nullable NSError *)error {
/// Report the badge number after registration
if (!error) {
/// Reset the application badge. `-1`: Do not clear the notification bar; `0`: Clear the notification bar
[XGPush defaultManager].xgApplicationBadgeNumber = -1;
/// Reset the server badge base
[[XGPush defaultManager] setBadge:0];
}
}
/// Timing for calling a hot start
/// The hot start tag `_launchTag` is managed by the business.
- (void)xgPushNetworkConnected {
if (_launchTag) {
/// Reset the application badge. `-1`: Do not clear the notification bar; `0`: Clear the notification bar
[XGPush defaultManager].xgApplicationBadgeNumber = -1;
/// Reset the server badge base
[[XGPush defaultManager] setBadge:0];
_launchTag = NO;
}
}
This API can be used to set the polling time (minimum: 10s; default: 258s) of in-app messages.
/// Set the message polling time interval (minimum: 10s). This API should be called before the singleton initialization.
- (void)setMessageTimerInterval:(NSTimeInterval)interval;
NSTimeInterval
: NSTimeInterval
type; the in-app message polling time interval
You can obtain custom event parameters through the proxy method onClickWithCustomAction
to handle related businesses.
/// Button event response proxy
@property (weak, nonatomic, nullable) id<XGInAppMessageActionDelegate> actionDelegate;
This API is used to query whether the user allows device notifications.
- (void)deviceNotificationIsAllowed:(nonnull void (^)(BOOL isAllowed))handler;
handler
: result return method
[[XGPush defaultManager] deviceNotificationIsAllowed:^(BOOL isAllowed) {
<#code#>
}];
This API is used to query the current SDK version.
- (nonnull NSString *)sdkVersion;
[[XGPush defaultManager] sdkVersion];
If you find push exceptions, you can call this API to trigger the reporting of local push logs. When you submit a ticket to report the problem, provide us the file address to facilitate troubleshooting.
/// @note Tencent Push Notification Service SDK v1.2.4.1+
- (void)uploadLogCompletionHandler:(nullable void(^)(BOOL result, NSString * _Nullable errorMessage))handler;
@brief
: report log information (SDK v1.2.4.1+).@param handler
: report callback[[XGPush defaultManager] uploadLogCompletionHandler:nil];
This method is used to get Tencent Push Notification Service logs, which is irrelevant to XGPush > enableDebug
.
logInfo
: log information
- (void)xgPushLog:(nullable NSString *)logInfo;
This API is used to create a click event in the notification message.
+ (nullable id)actionWithIdentifier:(nonnull NSString *)identifier title:(nonnull NSString *)title options:(XGNotificationActionOptions)options;
identifier
: unique ID of the action. title
: action name. options
: options supported by the action.XGNotificationAction *action1 = [XGNotificationAction actionWithIdentifier:@"xgaction001" title:@"xgAction1" options:XGNotificationActionOptionNone];
Note:The notification bar has the event click feature, which is only supported in iOS 8.0 and later. For iOS 7.x or earlier, this method will return null.
This API is used to create a category object to manage the action object of the notification bar.
+ (nullable id)categoryWithIdentifier:(nonnull NSString *)identifier actions:(nullable NSArray<id> *)actions intentIdentifiers:(nullable NSArray<NSString *> *)intentIdentifiers options:(XGNotificationCategoryOptions)options
identifier
: category object ID.actions
: action object group included in the current category.intentIdentifiers
: identifiers that can be recognized by Siri.options
: category characteristics.Note:The notification bar has the event click feature, which is only supported in iOS 8.0 and later. For versions earlier than iOS 8.0, this method will return null.
XGNotificationCategory *category = [XGNotificationCategory categoryWithIdentifier:@"xgCategory" actions:@[action1, action2] intentIdentifiers:@[] options:XGNotificationCategoryOptionNone];
This API is used to manage the style and characteristics of the push message notification bar.
+ (nullable instancetype)configureNotificationWithCategories:(nullable NSSet<id> *)categories types:(XGUserNotificationTypes)types;
categories
: a collection of categories supported by the notification bar. types
: the style of the device registration notification.XGNotificationConfigure *configure = [XGNotificationConfigure configureNotificationWithCategories:[NSSet setWithObject:category] types:XGUserNotificationTypeAlert|XGUserNotificationTypeBadge|XGUserNotificationTypeSound];
For more information about the local push feature, click here.
Was this page helpful?