The following are device registration API methods. For more information on the timing and principle of calls, see Device registration flow.
Launch the TPNS service by using the information of the application registered at the official website of TPNS.
- (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, TPNS 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, please see Device unregistration flow.
After the TPNS service is stopped, the application will not be able to push messages to devices through TPNS. To receive messages pushed by TPNS again, you must call the startXGWithAccessID:accessKey:delegate:
method again to restart the TPNS service.
- (void)stopXGNotification;
[[XGPush defaultManager] stopXGNotification];
This API is used to query the token string generated by the current application on the TPNS server.
@property (copy, nonatomic, nullable, readonly) NSString *xgTokenString;
NSString *token = [[XGPushTokenManager defaultTokenManager] xgTokenString];
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 TPNS, which needs to be used during message push. TPNS maintains the mapping relationship between this value and the device token generated by APNs.error
: error message. If error
is nil
, TPNS has been successfully registered.This is a callback for TPNS registration failures.
- (void)xgPushDidFailToRegisterDeviceTokenWithError:(nullable NSError *)error
This is a callback for notification pop-up window authorization results.
- (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, please see Account flow.
If there is no account of this type, it will add a new one; otherwise, it will overwrite the existing one.
- (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"}
.
- (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:@"13712345678"];;
Note:
- This API should be called after
xgPushDidRegisteredDeviceToken:error:
returns a success.- You can call
delAccountsByKeys:[[NSSet alloc] initWithObjects:@(1002), nil]
to delete a mobile number.
This API is used to delete all accounts of a specified account type.
- (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
, please 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, please 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 (if you want to increase this limit, please 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 used to query tags bound to a 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 is a callback for tag query results.
- (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, please 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.- Objective-C syntax: @{@"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:A set is required and the key is fixed.
[[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 TPNS 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:After the local badge number is set for the application, call this API to sync it to the TPNS server, which will take effect in the next push. This API must be called after successful TPNS registration (
xgPushDidRegisteredDeviceToken
).
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/// Zero the badge number every time the application is started (you should set the local badge number for the application in the main thread)
if ([XGPush defaultManager].xgApplicationBadgeNumber > 0) {
[XGPush defaultManager].xgApplicationBadgeNumber = 0;
}
return YES;
}
- (void)xgPushDidRegisteredDeviceToken:(nullable NSString *)deviceToken xgToken:(nullable NSString *)xgToken error:(nullable NSError *)error {
/// Sync the badge number to TPNS after registration
if (!error) {
[[XGPush defaultManager] setBadge:0];
}
}
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 reporting of local push logs. To report the problem, submit a ticket with the file address provided to facilitate troubleshooting.
- (void)uploadLogCompletionHandler:(nullable void(^)(BOOL result, NSString * _Nullable errorMessage))handler;
@brief
: report log information@param handler
: report callback[[XGPush defaultManager] uploadLogCompletionHandler:nil];
This method is used to get TPNS logs, which is irrelevant to XGPush > enableDebug
.
logInfo
: log information
- (void)xgPushLog:(nullable NSString *)logInfo;
For more information about the local push feature, please click here.
Was this page helpful?