API Documentation

Last updated: 2020-03-18 11:20:04

PDF

Launch Tencent Mobile push Service

Interface description

Launch Tencent Mobile push service by using the application information registered on the official website of Tencent Mobile push.

- (void)startXGWithAppID:(uint32_t)appID appKey:(nonnull NSString *)appKey delegate:(nullable id<XGPushDelegate>)delegate ;

Parameter description

  • The application ID, that AppID: applies for through the front desk is Access ID.
  • The appKey, that AppKey: applied for through the front desk is Access Key.
  • Delegate: callback object.

The parameters required for the API must be correct, Enter, otherwise Tencent Mobile push service will not be able to correctly push messages for the application.

Sample code

[[XGPush defaultManager] startXGWithAppID: <#your access ID#>appKey:<#your access key#> delegate:<#your delegate#>];

Terminate Tencent Mobile push service

Interface description

After terminating Tencent Mobile push service, you will not be able to push messages to Device through Tencent Mobile push service. If you need to receive message push from Tencent Mobile push service again, you must call the startXGWithAppID:appKey:delegate: Method restart Tencent mobile push service.

- (void)stopXGNotification;

Sample code

[[XGPush defaultManager] stopXGNotification];

Customize the notification bar message behavior

Create a behavior supported by messages

Interface description

Create a tappable event action in the notification message.

+ (nullable id)actionWithIdentifier:(nonnull NSString *)identifier title:(nonnull NSString *)title options:(XGNotificationActionOptions)options;

Parameter description

  • The identifier: behavior is uniquely identified.
  • Title: behavior name.
  • Options supported by the options: behavior.

Sample code

XGNotificationAction *action1 = [XGNotificationAction actionWithIdentifier:@"xgaction001" title:@"xgAction1" options:XGNotificationActionOptionNone];

The notification bar has the feature of click event, which is only supported above iOS8.0 +, the version of iOS 7.x or earlier. This method returns null.

Create classified object

Interface description

Create a classification object to manage the Action object of the notification bar.

+ (nullable id)categoryWithIdentifier:(nonnull NSString *)identifier actions:(nullable NSArray<XGNotificationAction *> *)actions intentIdentifiers:(nullable NSArray<NSString *> *)intentIdentifiers options:(XGNotificationCategoryOptions)options;

Parameter description

  • Identification of the identifier: classification object.
  • The group of behavior objects owned by the current classification of actions:.
  • IntentIdentifiers: is used to indicate identities that can be identified by Siri.
  • Characteristics of options: classification.

The notification bar has the feature of click event, which is only supported above iOS8+, the version of iOS8 or earlier. This method returns null.

Sample code

XGNotificationCategory *category = [XGNotificationCategory categoryWithIdentifier:@"xgCategory" actions:@[action1, action2] intentIdentifiers:@[] options:XGNotificationCategoryOptionNone];

Create a configuration class

Interface description

Manage the style and characteristics of the push message notification bar.

+ (nullable instancetype)configureNotificationWithCategories:(nullable NSSet<XGNotificationCategory *> *)categories types:(XGUserNotificationTypes)types;

Parameter description

  • A collection of categories supported in the categories: notification bar.
  • The style of the types: registration notification.

Sample code

XGNotificationConfigure *configure = [XGNotificationConfigure configureNotificationWithCategories:[NSSet setWithObject:category] types:XGUserNotificationTypeAlert|XGUserNotificationTypeBadge|XGUserNotificationTypeSound];

Add 1 automatically to the corner mark

Interface description

Call this API to report the current number of App corner marks to Tencent Mobile push server. After the client is configured, you can use the feature of "iOS corner auto plus 1". This feature is located in the console (create push > Notification Bar message > Common Settings > Corner number).

- (void)setBadge:(NSInteger)badgeNumber;

Parameter description

The number of corner marks applied by badgeNumber:.

This API must be called locally, otherwise the corner label will remain unchanged by default when the console uses the "iOS corner auto plus 1" function.

Sample code

[[XGPush defaultManager] setBadge:7];

Management application corner

Interface description

Manages the number of corner markers displayed by App. This interface needs to be called in the main thread.

@property (nonatomic) NSInteger xgApplicationBadgeNumber;

Sample code

// Set the app badge
[[XGPush defaultManager] setXgApplicationBadgeNumber:0];

// Get the app badge
NSInteger number = [[XGPush defaultManager] xgApplicationBadgeNumber];

Manage Device Token

Query Device Token

Interface description

Query the Token string obtained from APNs by the current application.

@property (copy, nonatomic, nullable, readonly) NSString *deviceTokenString;

Sample code

NSString *token = [[XGPushTokenManager defaultTokenManager] deviceTokenString];

Query XGToken

Interface description

Query the Token string generated by the current application from Tencent Mobile push server.

@property (copy, nonatomic, nullable, readonly) NSString *xgTokenString;

Sample code

NSString *token = [[XGPushTokenManager defaultTokenManager] xgTokenString];

Query APNs registration result

Interface description

If the registration is successful, the application will call the UIApplicationDelegate The callback method of Proxy object (as follows ).

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;

Query the registration result of Tencent Mobile push

Interface description

SDK's Launch method automatically registers the Token obtained by Device from APNs to Tencent Mobile push server, and the registration result will be in XGPushDelegate (below Is returned by the callback method of

- (void)xgPushDidRegisteredDeviceToken:(NSString *)deviceToken error:(NSError *)error;

This callback method is called after the registration is successful. After the current Token has been registered, the SDK will cache the registration information, and this method will not be called again.

Bind / Unbind tag and account

Interface description

Developers can bind tags for different users and then push the tag.

This interface should be called after the xgPushDidRegisteredDeviceToken:error: returns correctly.

Single operation interface

- (void)bindWithIdentifier:(nullable NSString *)identifier type:(XGPushTokenBindType)type;
- (void)unbindWithIdentifer:(nullable NSString *)identifier type:(XGPushTokenBindType)type;

Parameter description

  • Identifier: tag or account number.
  • Type: binding type.

Sample code

// Bind the tag:
[[XGPushTokenManager defaultTokenManager] bindWithIdentifier:@"your tag" type:XGPushTokenBindTypeTag];

// Unbind the tag
[[XGPushTokenManager defaultTokenManager] unbindWithIdentifer:@"your tag" type:XGPushTokenBindTypeTag];

// Bind an account:
[[XGPushTokenManager defaultTokenManager] bindWithIdentifier:@"your account" type:XGPushTokenBindTypeAccount];

//Unbind an account:
[[XGPushTokenManager defaultTokenManager] unbindWithIdentifer:@"your account" type:XGPushTokenBindTypeAccount];

Batch operation interface

- (void)bindWithIdentifiers:(nonnull NSArray <NSString *> *)identifiers type:(XGPushTokenBindType)type
- (void)unbindWithIdentifers:(nonnull NSArray <NSString *> *)identifiers type:(XGPushTokenBindType)type;

Parameter description

  • Identifiers: tag or account list.
  • Type: binding type.

Tags or account strings do not allow spaces or tab characters.

Update tags / accounts in batch

Interface description

Overwrite the original ID (tag / account). If the ID is not previously bound, the new ID will be performed.

This interface should be called after the xgPushDidRegisteredDeviceToken:error: returns correctly.

- (void)updateBindedIdentifiers:(nonnull NSArray <NSString *> *)identifiers bindType:(XGPushTokenBindType)type;

Parameter description

  • The identifiers: tag identifies an array of strings. Label strings do not allow spaces or tab characters.
  • Type: identity type.

If you specify the tag type, this API will replace all the old tags corresponding to the current Token with the current tags; if you specify the account type, this API will only take the first one in the identifiers list.

Clear all tags / accounts

Interface description

Clear all identities according to the identity type.

This interface should be called after the xgPushDidRegisteredDeviceToken:error: returns correctly.

- (void)clearAllIdentifiers:(XGPushTokenBindType)type;

Parameter description
Type: identity type.

Query bound tags and accounts

Interface description

Queries the identity of the current Token object binding based on the specified type.

This interface should be called after the xgPushDidRegisteredDeviceToken:error: returns correctly.

- (nullable NSArray<NSString *> *)identifiersWithType:(XGPushTokenBindType)type;

Sample code

// Query the tag
[[XGPushTokenManager defaultTokenManager] identifiersWithType:XGPushTokenBindTypeTag];
// Query the account
[[XGPushTokenManager defaultTokenManager] identifiersWithType:XGPushTokenBindTypeAccount];

Inquire about Device and inform Permission

Interface description

Inquire whether Device informs Permission whether it is allowed by the user.

- (void)deviceNotificationIsAllowed:(nonnull void (^)(BOOL isAllowed))handler;

Parameter description

The return method of the handler: query result.

Sample code

[[XGPush defaultManager] deviceNotificationIsAllowed:^(BOOL isAllowed) {
        <#code#>
    }];

Query SDK version

Interface description

Query the current version of SDK.

- (nonnull NSString *)sdkVersion;

Sample code

[[XGPush defaultManager] sdkVersion];

Log reporting interface

Interface description

If developers find that the push-related features are abnormal, they can call this API to trigger the report of the local push log. When reporting problems, please provide us with the file address to facilitate troubleshooting.

- (void)uploadLogCompletionHandler:(nullable void(^)(BOOL result,  NSString * _Nullable errorMessage))handler;

Parameter description

  • @ brief: reports log information (SDK1.2.4.1+).
  • @ param handler: reports callback.

Sample code

[[XGPush defaultManager] uploadLogCompletionHandler:nil];

Free cluster anti-registration

Interface description

Background: if App migrates from a free cluster to a paid cluster, there may be duplicate messages when both clusters are pushed at the same time. Therefore, you need to call this API. SDK will unregister Device's information in the free cluster.
Import header file: XGForFreeVersion.h, is called before startXGWithAppID

@property uint32_t freeAccessId;

Parameter description

  • AccessId (SDK1.2.5.3+) of the @ freeAccessId free cluster.

Sample code

[XGForFreeVersion defaultForFreeVersion].freeAccessId = 2200262432;

Local push

For related functions of local push, please refer to Apple developer documentation .