+ (void)startSdkWithAppId:(NSString *)appid appKey:(NSString *)appKey appSecret:(NSString *)appSecret delegate:(id<GeTuiSdkDelegate>)delegate launchingOptions:(NSDictionary * __nullable)launchOptions;
GeTuiSdkDelegate
回调接口返回 cid 信息。[GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self launchingOptions:launchingOptions];
// 通过 appId、 appKey 、appSecret 启动SDK,注:该方法需要在主线程中调用
/// [ GTSDK回调 ] SDK启动成功返回cid
- (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
NSLog(@"[ TestDemo ] [GTSdk RegisterClient]:%@", clientId);
}
+ (void)registerRemoteNotification:(UNAuthorizationOptions)types;
[GeTuiSdk registerDeviceTokenData:deviceToken]
关联。UNAuthorizationOptions types = (UNAuthorizationOptionBadge |
UNAuthorizationOptionAlert |
UNAuthorizationOptionSound);
[GeTuiSdk registerRemoteNotification:types];
- (void)GeTuiSDkDidNotifySdkState:(SdkStatus)status;
- (void)GeTuiSDkDidNotifySdkState:(SdkStatus)status {
NSLog(@"[GetuiSdk Status]:%u", status);
}
- (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification * )notification
completionHandler:(void (^) (UNNotificationPresentationOptions))completionHandler;
userNotificationCenter: willPresentNotification: withCompletionHandler:
展示回调。开发者需要调用个推注册远程通知[GeTuiSdk registerRemoteNotification]
。- (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification completionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APNs] %@ \n%@", NSStringFromSelector(_cmd), notification.request.content.userInfo];
[self.homePage logMsg:msg];
// [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要,判断是否要提示用户Badge、Sound、Alert等
//completionHandler(UNNotificationPresentationOptionNone); 若不显示通知,则无法点击通知
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}
- (void)GeTuiSdkDidReceiveNotification:(NSDictionary *)userInfo
notificationCenter:(nullable UNUserNotificationCenter *)center
response:(nullable UNNotificationResponse *)response
fetchCompletionHandler:(nullable void (^)(UIBackgroundFetchResult))completionHandler;
application: didReceiveRemoteNotification: fetchCompletionHandler:
和userNotificationCenter: didReceiveNotificationResponse: withCompletionHandler:
通知回调。开发者需要调用个推注册远程通知[GeTuiSdk registerRemoteNotification]
。application: didReceiveRemoteNotification: fetchCompletionHandler:
和 当前方法,要注意只保留一个completionHandler调用,调用多次可能多导致偶现crash。- (void)GeTuiSdkDidReceiveNotification:(NSDictionary *)userInfo notificationCenter:(UNUserNotificationCenter *)center response:(UNNotificationResponse *)response fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APNs] %@ \n%@", NSStringFromSelector(_cmd), userInfo];
[self.homePage logMsg:msg];
if(completionHandler) {
// [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要自行修改参数值
completionHandler(UIBackgroundFetchResultNoData);
}
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler
{
//注意,如果执行了上述代理方法中的completionHandler,就不要执行当前回调中的completionHandler。
//防止两次调用completionHandler引起崩溃
//completionHandler(UIBackgroundFetchResultNewData);
}
- (void)GeTuiSdkDidReceiveSlience:(NSDictionary *)userInfo
fromGetui:(BOOL)fromGetui
offLine:(BOOL)offLine
appId:(nullable NSString *)appId
taskId:(nullable NSString *)taskId
msgId:(nullable NSString *)msgId
fetchCompletionHandler:(nullable void (^)(UIBackgroundFetchResult))completionHandler;
GeTuiSdkDelegate
将收到回调且offLine=NO。如果下发时cid离线,消息将存入个推离线服务器,通过苹果APNS发送静默消息通知。 cid在线后将收到本条消息且offLine=YES。application: didReceiveRemoteNotification: fetchCompletionHandler:
通知回调,处理来自苹果APNs的静默消息通知回调。开发者需要调用个推注册远程通知[GeTuiSdk registerRemoteNotification]
。- (void)GeTuiSdkDidReceiveSlience:(NSDictionary *)userInfo fromGetui:(BOOL)fromGetui offLine:(BOOL)offLine appId:(NSString *)appId taskId:(NSString *)taskId msgId:(NSString *)msgId fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APN] %@ \nReceive Slience: fromGetui:%@ appId:%@ offLine:%@ taskId:%@ msgId:%@ userInfo:%@ ", NSStringFromSelector(_cmd), fromGetui ? @"个推消息" : @"APNs消息", appId, offLine ? @"离线" : @"在线", taskId, msgId, userInfo];
[self.homePage logMsg:msg];
if(completionHandler) {
// [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要自行修改参数值
completionHandler(UIBackgroundFetchResultNoData);
}
}
//以下处理用于推送苹果在线透传消息时,补全上报个推渠道消息点击数;需通过上述userInfo的_gmid_中获取到taskId 和msgId,_gmid_组成格式是taskId:msgId:clientid,以冒号区分;在您自身点击事件逻辑触发时,执行上报埋点,点击id固定为60002。
// [GeTuiSdk sendFeedbackMessage:60002 andTaskId:taskId andMsgId:msgId];
- (void)GetuiSdkGrantAuthorization:(BOOL)granted error:(NSError *)error;
[GeTuiSdk registerRemoteNotification]
。GetuiSdkGrantAuthorization
告知开发者。- (void)GetuiSdkGrantAuthorization:(BOOL)granted error:(NSError *)error {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APNs] %@ \n%@ %@", NSStringFromSelector(_cmd), @(granted), error];
NSLog(@"%@", msg);
}
- (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center
openSettingsForNotification:(nullable UNNotification *)notification
userNotificationCenter: openSettingsForNotification:
通知设置回调。开发者需要调用个推注册远程通知[GeTuiSdk registerRemoteNotification]
。+ (BOOL)sendFeedbackMessage:(NSInteger)actionId andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId;
第三方自定义回执,可用于数据统计。
/// [ GTSDK回调 ] SDK收到透传消息回调
- (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId {
// [ GTSDK ]:汇报个推自定义事件(反馈透传消息)
[GeTuiSdk sendFeedbackMessage:90001 andTaskId:taskId andMsgId:msgId];
}
+ (NSString*) handleApplinkFeedback:(NSURL* )webUrl;
/// [ 系统回调 ] APPLink回调
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler {
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSURL *webUrl = userActivity.webpageURL;
// [ GTSDK ]:处理个推APPLink回执统计
// APPLink url 示例:https://link.gl.ink/getui?n=payload&p=mid, 其中 n=payload 字段存储用户透传信息,可以根据透传内容进行业务操作。
NSString *payload = [GeTuiSdk handleApplinkFeedback:webUrl];
if (payload) {
NSLog(@"[ TestDemo ] 个推APPLink中携带的用户payload信息: %@,URL : %@", payload, webUrl);
// TODO: 用户可根据具体 payload 进行业务处理
}
}
return YES;
}
+ (void)setPushModeForOff:(BOOL)isValue;
- (void)GeTuiSdkDidSetPushMode:(BOOL)isModeOff error:(NSError *)error
;具体可参考GeTuiSdkDelegate 回调中的说明。[GeTuiSdk setPushModeForOff:NO];
- (void)GeTuiSdkDidSetPushMode:(BOOL)isModeOff error:(NSError *)error {
if (error) {
NSString* errorInfo = [NSString stringWithFormat:@">>>[SetModeOff error]: %@", [error localizedDescription]];
NSLog(@"GeTuiSdkDidSetPushMode with error : %@", errorInfo);
return;
}
NSString* settingInfo = [NSString stringWithFormat:@">>>[GexinSdkSetModeOff]: %@", isModeOff ? @"开启" : @"关闭"];
NSLog(@"%@", settingInfo);
}
+ (BOOL)setTags:(NSArray *)tags;
+ (BOOL)setTags:(NSArray *)tags andSequenceNum:(NSString *)aSn;
- (void)GeTuiSdkDidSetTagsAction:(NSString *)sequenceNum result:(BOOL)isSuccess error:(NSError *)aError;
。[GeTuiSdk setTags:@[@"标签1",@"标签2",@"标签3"]];
[GeTuiSdk setTags:@[@"标签1",@"标签2",@"标签3" andSequenceNum:@"seqtag-1"];
- (void)GeTuiSdkDidSetTagsAction:(NSString *)sequenceNum result:(BOOL)isSuccess error:(NSError *)aError {
/*
参数说明
sequenceNum: 请求的序列码
isSuccess: 操作成功 YES, 操作失败 NO
aError.code:
20001:tag 数量过大(单次设置的 tag 数量不超过 100)
20002:调用次数超限(默认一天只能成功设置一次)
20003:标签重复
20004:服务初始化失败
20005:setTag 异常
20006:tag 为空
20007:sn 为空
20008:离线,还未登陆成功
20009:该 appid 已经在黑名单列表(请联系技术支持处理)
20010:已存 tag 数目超限
20011:tag 内容格式不正确
*/
NSLog(@"GeTuiSdkDidSetTagAction sequenceNum:%@ isSuccess:%@ error: %@", sequenceNum, @(isSuccess), aError);
}
+ (void)bindAlias:(NSString *)alias andSequenceNum:(NSString *)aSn;
GeTuiSdkDidAliasAction:(NSString *)action result:(BOOL)isSuccess sequenceNum:(NSString *)aSn error:(NSError *)aError
;具体可参考GeTuiSdkDelegate 回调中的说明。[GeTuiSdk bindAlias:@"个推" andSequenceNum:@"seq-1"];
- (void)GeTuiSdkDidAliasAction:(NSString *)action result:(BOOL)isSuccess sequenceNum:(NSString *)aSn error:(NSError *)aError {
/*
参数说明
isSuccess: 操作成功 YES, 操作失败 NO
aError.code:
30001:操作别名失败,频率过快,两次调用的间隔需大于 5s
30002:操作别名失败,参数错误
30003:当前 cid 绑定别名次数超限
30004:操作别名失败,未知异常
30005:操作别名时,cid 未获取到
30006:操作别名时,发生网络错误
30007:别名无效
30008:sn 无效 */
if([action isEqual:kGtResponseBindType]) {
NSLog(@"[ TestDemo ] bind alias result sn = %@, code = %@", aSn, @(aError.code));
}
if([action isEqual:kGtResponseUnBindType]) {
NSLog(@"[ TestDemo ] unbind alias result sn = %@, code = %@", aSn, @(aError.code));
}
}
+ (void)unbindAlias:(NSString *)alias andSequenceNum:(NSString *)aSn andIsSelf:(BOOL) isSelf;
请求回调同绑定别名
GeTuiSdk.h
[GeTuiSdk unbindAlias:@"个推" andSequenceNum:@"seq-1" andIsSelf:YES];
+ (void)setBadge:(NSUInteger)value;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge]
进行设置。[GeTuiSdk setBadge:5];
//如果需要角标显示需要调用系统方法设置
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:5];
+ (void)resetBadge;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
进行设置。//重置角标
[GeTuiSdk resetBadge];
//如果需要角标清空需要调用系统方法设置
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
+ (void)clearAllNotificationForNotificationBar;
//清空通知和角标
[GeTuiSdk clearAllNotificationForNotificationBar];
+ (NSString *)clientId;
17. 获取回调CID
接口中的 cid 为准)[GeTuiSdk clientId];
- (void)GeTuiSdkDidRegisterClient:(NSString *)clientId;
- (void)GeTuiSdkDidRegisterClient:(NSString *)clientId
;具体可参考GeTuiSdkDelegate 回调中的说明。- (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
NSLog(@"[GetuiSDK ClientId]:%@", clientId);
}
+ (SdkStatus)status;
[GeTuiSdk status];
+ (NSString *)version;
[GeTuiSdk version];
+ (void)setChannelId:(NSString *)channelId;
//设置渠道信息
[GeTuiSdk setChannelId:@"GT-Channel"];
+ (BOOL)registerVoipTokenCredentials:(NSData *)voipToken;
/// [ 系统回调 ]
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
//向个推服务器注册 VoipToken
[GeTuiSdk registerVoipTokenCredentials:credentials.token];
}
+ (void)handleVoipNotification:(NSDictionary *)payload;
警告:在iOS 13 之后 Apple不再允许PushKit应用在非Voip电话的场景下,如果需要使用Pushkit则需要接入Callkit的接口。若需要实现语音播报功能,建议通过通知扩展实现,具体参考官方Demo;
/// [ 系统回调 ]
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
//TODO:接收 VOIP 推送中的 Payload 信息进行业务处理。
NSLog(@"[Voip Payload]:%@,%@", payload, payload.dictionaryPayload);
//调用个推 VOIP 回执统计接口
[GeTuiSdk handleVoipNotification:payload.dictionaryPayload];
}
+ (void)runBackgroundEnable:(BOOL)isEnable;
[GeTuiSdk runBackgroundEnable:YES];
+ (void)lbsLocationEnable:(BOOL)isEnable andUserVerify:(BOOL)isVerify;
[GeTuiSdk lbsLocationEnable:YES andUserVerify:YES];
+ (NSString *)sendMessage:(NSData *)body error:(NSError **)error;
+ (NSString *)sendMessage:(NSData *)body taskId:(NSString *)taskId error:(NSError **)error;
- (void)GeTuiSdkDidSendMessage:(NSString *)messageId result:(int)result
;具体可参考GeTuiSdkDelegate 回调中的说明。 NSError *aError = nil;
NSData *sendData = [@"sendMessage" dataUsingEncoding:NSUTF8StringEncoding];
[GeTuiSdk sendMessage:sendData error:&aError]
- (void)GeTuiSdkDidSendMessage:(NSString *)messageId result:(int)result {
//消息推送到个推服务器,服务器通过该接口通知sdk到达结果,result 为1 说明消息发送成功,0为失败。
//注意: 需第三方服务器接入个推,SendMessage 到达第三方服务器后返回 1。
NSString *msg = [NSString stringWithFormat:@"Received sendmessage:%@ result:%d", messageId, result];
NSLog(@"[ TestDemo ] [GeTuiSdk DidSendMessage]:%@\n\n",msg);
}
+ (void)setApplicationGroupIdentifier:(NSString*)identifier;
[GeTuiSdk setApplicationGroupIdentifier:]
和[GeTuiExtSdk setApplicationGroupIdentifier:]
,用于回执报表统计。 [GeTuiSdk setApplicationGroupIdentifier:苹果开发者后台设置的Group Identify];
+ (void)handelNotificationServiceRequest:(UNNotificationRequest *)request withAttachmentsComplete:(void (^)(NSArray* attachments, NSArray* errors))completeBlock;
UNNotificationAttachment
组成的数组NSError
组成的数组1).接收到 APNs 通知后,SDK 判断是否有多媒体资源,如果多媒体资源存在则下载资源,下载完成后以 Block 方式回调返回 attachments 资源数组对象和 errors 错误数组信息。
2).多媒体大小限制:
资源 | 类型 | 大小 | 超时 |
---|---|---|---|
图片 | 1 | <=10MB | 120s |
音频 | 2 | <=5MB | 60s |
视频 | 3 | <=50MB | 180s |
3).可设置是否仅在 WIFI 下下载资源,参考服务端API。如果为True,数据网络下将不下载资源,展示通知不带附件。默认是False,支持 WIFI 和 数据网络下下载。
4). 资源URL格式注意:不支持中文及转译地址,请使用英文合法地址。
5). 错误信息:
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
NSLog(@"----将APNs信息交由个推处理----");
[GeTuiExtSdk handelNotificationServiceRequest:request withAttachmentsComplete:^(NSArray *attachments, NSArray* errors) {
//TODO:用户可以在这里处理通知样式的修改,eg:修改标题
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title]; //修改展示title信息
self.bestAttemptContent.attachments = attachments; //设置通知中的多媒体附件
NSLog(@"个推处理APNs消息遇到错误:%@",errors); //如果APNs处理有错误,可以在这里查看相关错误详情
self.contentHandler(self.bestAttemptContent); //展示推送的回调处理需要放到个推回执完成的回调中
}];
}
+ (void)handelNotificationServiceRequest:(UNNotificationRequest *) request withComplete:(void (^)(void))completeBlock;
只统计APNs到达情况,不下载多媒体资源
,完成后以 block方式回调,用户可在此回调中自行修改通知样式等。self.contentHandler(self.bestAttemptContent)
来完成更新通知栏的正常展示。- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
//通知个推服务器APNs信息送达
[GeTuiExtSdk handelNotificationServiceRequest:request withComplete:^{
// Modify the notification content here...
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
//返回新的通知内容,展示APNs通知。
self.contentHandler(self.bestAttemptContent);
}];
}
+ (void)destory;
- (void)serviceExtensionTimeWillExpire {
//超时时销毁个推SDK释放资源
[GeTuiExtSdk destory];
self.contentHandler(self.bestAttemptContent);
}
- (void)GeTuiSdkDidOccurError:(NSError *)error;
/** SDK遇到错误回调 */
- (void)GeTuiSdkDidOccurError:(NSError *)error {
NSLog(@"[ TestDemo ] [GeTuiSdk GeTuiSdkDidOccurError]:%@\n\n",error.localizedDescription);
}
+ (BOOL)registerLiveActivity:(NSString *)liveActivityId activityToken:(NSString*)token sequenceNum:(NSString*)sn;
for await tokenData in current.pushTokenUpdates {
let mytoken = tokenData.map { String(format: "%02x", $0) }.joined()
[GeTuiSdk registerLiveActivity:@"订单号" activityToken:mytoken sequenceNum:@"序列号"];
}
- (void)GeTuiSdkDidRegisterLiveActivity:(NSString *)sequenceNum result:(BOOL)isSuccess error:(NSError *)error {
NSLog(@"GeTuiSdkDidRegisterLiveActivity SN: %@, isSuccess : %@, error :%@", sequenceNum, @(isSuccess), error);
}
// 弹窗展示回调
- (void)GeTuiSdkPopupDidShow:(NSDictionary *)info;
// 弹窗点击回调
- (void)GeTuiSdkPopupDidClick:(NSDictionary *)info;
// 展示回调
- (void)GeTuiSdkPopupDidShow:(NSDictionary *)info {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] GeTuiSdkPopupDidShow%@", info];
[self.homePage logMsg:msg];
//已经集成用户运营SDK的用户, 建议调用IDO的应用内弹窗统计
[GTCountSDK popupDidShow:info];
}
// 点击回调
- (void)GeTuiSdkPopupDidClick:(NSDictionary *)info {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] GeTuiSdkPopupDidClick%@", info];
[self.homePage logMsg:msg];
//已经集成用户运营SDK的用户, 建议调用IDO的应用内弹窗统计
[GTCountSDK popupDidClick:info];
}
以上文档对您是否有帮助?