Commit 3c4f4385 by pierce

消息推送相关的配送

parent b83b878b
......@@ -184,6 +184,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 获取背包最后更新的时间
+ (NSString *)fus_URL_requestBackpackTimeUpdateGet;
// 用户点击个推消息-记录
+ (NSString *)fus_URL_UploadPushClickLog;
@end
NS_ASSUME_NONNULL_END
......@@ -288,4 +288,9 @@
}
// 用户点击个推消息-记录
+ (NSString *)fus_URL_UploadPushClickLog {
return [FUSConfig.sharedInstanced.pathConfigs apiUrl:@"/stat/clickPushMsg/log"];
}
@end
......@@ -13,12 +13,13 @@
#import <FirebaseCore/FIRApp.h>
#import <FirebaseAnalytics/FirebaseAnalytics.h>
#import <FUSCommon/FUSCommonURLs.h>
#import <FUSFoundation/FUSFoundation.h>
static NSString *const kGtAppId = @"2ecfODySFs8GlqYu7H2hW9";
static NSString *const kGtAppKey = @"tjOur8OKTU7srFHoA0lB91";
static NSString *const kGtAppSecret = @"OSSSWqbWY0ACJiUv4AHdW7";
@interface AppDelegate ()<UNUserNotificationCenterDelegate, GeTuiSdkDelegate>
@interface AppDelegate ()<UNUserNotificationCenterDelegate, GeTuiSdkDelegate,UIApplicationDelegate>
@end
......@@ -45,6 +46,13 @@ static NSString *const kGtAppSecret = @"OSSSWqbWY0ACJiUv4AHdW7";
// 通过 个推平台 分配的appId、 appKey 、appSecret 启动SDK,注:该方法需要在主线程中调用
[GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self launchingOptions:launchOptions];
[GeTuiSdk registerRemoteNotification:UNAuthorizationOptionSound|UNAuthorizationOptionAlert|UNAuthorizationOptionBadge];
[GeTuiSdk runBackgroundEnable:NO];
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:UNAuthorizationOptionBadge|UNAuthorizationOptionSound|UNAuthorizationOptionAlert completionHandler:^(BOOL granted, NSError * _Nullable error) {
}];
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
[UIApplication.sharedApplication registerForRemoteNotifications];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[FIRApp configure];
......@@ -61,7 +69,7 @@ static NSString *const kGtAppSecret = @"OSSSWqbWY0ACJiUv4AHdW7";
[FUSAPIDNSManager fus_checkCurrentDNSAddress];
// 设置webimage 最大100M
// [YYWebImageManager sharedManager].cache.diskCache.costLimit = 100*1024*1024;
// [YYWebImageManager sharedManager].cache.diskCache.costLimit = 100*1024*1024;
[NSURLCache sharedURLCache].diskCapacity = 100 * 1024 * 1024;
// 设置第三方登录相关框架
......@@ -76,6 +84,7 @@ static NSString *const kGtAppSecret = @"OSSSWqbWY0ACJiUv4AHdW7";
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:FUSLiveUDKeys.fus_SHOULD_REMOTE_NOTIFICATION_TIP];
return YES;
}
......@@ -134,19 +143,6 @@ static NSString *const kGtAppSecret = @"OSSSWqbWY0ACJiUv4AHdW7";
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
FUSLogInfo(@"Received push notification: %@", notification); // iOS 7 and earlie
if (application.applicationState != UIApplicationStateActive) {
// 处理推送
NSString *jsonStr = [notification objectForKey:@"json"];
NSDictionary *jsonDict = [jsonStr converToDictionary];
[self fus_startJunmpIntoPage:jsonDict];
}
}
/// 用户点击推送 进入APP获取到的信息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
......@@ -172,22 +168,172 @@ static NSString *const kGtAppSecret = @"OSSSWqbWY0ACJiUv4AHdW7";
// iOS 10: 点击通知进入App时触发,在该方法内统计有效用户点击数
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
NSDictionary *dict = [response.notification.request.content.userInfo[@"transmissionContent"] converToDictionary];
NSDictionary *info = response.notification.request.content.userInfo;
NSString *fromUid = info[@"f"];
if (![NSString isNull:fromUid]) { //环信的消息格式
dict = @{@"type":@(3),@"data":@{@"userId":fromUid,@"nickname":@""}};
}
[self fus_startJunmpIntoPage:dict];
[self handleNotificationEventWithContent:response.notification.request.content.userInfo];
[self fus_handleChatLocalAPNsNotification:response];
// [ GTSdk ]:将收到的APNs信息传给个推统计
[GeTuiSdk handleRemoteNotification:response.notification.request.content.userInfo];
completionHandler();
}
- (void)fus_handleChatLocalAPNsNotification:(UNNotificationResponse *)response {
// 筛选聊天推送
NSString *identifier = response.notification.request.identifier;
if (![@"imnotice" isEqualToString:identifier]) {
return;
}
// 只在登录状态下写
if (FUSCacheDataShare.shareStore.userDetailInfo.uid == nil) {
return;
}
NSDictionary *userInfo = response.notification.request.content.userInfo;
[FUSRouter.chatRouter fus_chatWithUser:userInfo[@"uid"] nickname:@"" face:@""];
}
#endif
- (void)handleNotificationEventWithContent:(NSDictionary *)content {
// 个推
NSDictionary *transmissionContent = [content[@"transmissionContent"] converToDictionary];
NSString *fromUid = content[@"f"];
if ([NSString isNullWithString:fromUid] == NO) {
NSDictionary *ext = content[@"e"];
// 安卓有可能传的是String过来
if ([NSDictionary isNull:ext]) {
NSString *data = content[@"e"];
if ([NSString isNullWithString:data] == NO) {
ext = [data converToDictionary];
}
}
if ([NSDictionary isNull:ext]) {
// v7420以前的版本
transmissionContent = @{@"type":@3,@"data":@{@"userid":fromUid,@"nickname":@""}};
} else {
// 环信
transmissionContent = ext;
}
}
// 在線轉發個推的,內容放在content裡面
if (transmissionContent == nil) {
transmissionContent = content;
}
if ([NSDictionary isNull:transmissionContent] == NO) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (FUSCacheDataShare.shareStore.userDetailInfo.uid) {
[self startJumpIntoPage:transmissionContent];
}
});
}
}
- (void)startJumpIntoPage:(NSDictionary *)content {
// 如果还没登录的话,不需要做跳转操作
if (FUSCacheDataShare.shareStore.userDetailInfo.uid == nil) {
return;
}
NSInteger type = [content[@"type"] integerValue];
NSDictionary *info = content[@"data"];
if ([NSDictionary isNull:info] == NO) {
NSInteger pushType = [content[@"pushType"] integerValue];
NSInteger pushEventType = [content[@"pushEventType"] integerValue];
NSString *userId = nil;
if (info[@"userid"]) {
userId = info[@"userid"];
} else if (info[@"userId"]) {
userId = info[@"userId"];
}
[FUSAlertView fus_dismissAllAlertViewWithAnimate:YES];
// 移除所有window层的弹窗
UIView *rootSuperViewBelowWindow = UIApplication.sharedApplication.keyWindow.rootViewController.view.superview;
while (rootSuperViewBelowWindow.superview
&& rootSuperViewBelowWindow.superview != UIApplication.sharedApplication.keyWindow) {
rootSuperViewBelowWindow = rootSuperViewBelowWindow.superview;
}
for (UIView *view in UIApplication.sharedApplication.keyWindow.subviews) {
if (view != rootSuperViewBelowWindow) {
[view removeFromSuperview];
}
}
switch (type) {
case 0:
break;//进入首页
case 1: // 进入直播间
[FUSRouter.liveRouter fus_enterLiveRoom:userId];
break;
case 2: // 进入任务中心
case 4: // 进入动态内容详情页
[FUSRouter.userRouter fus_handlerUserModulePushEvent:type infor:info];
break;
case 3: // 进入单聊页面
[FUSRouter.chatRouter fus_chatWithUser:userId nickname:info[@"nickname"] face:info[@"face"]];
break;
case 5: { // 打开任意一个网页
FUSWKWebViewController *webVC = [[FUSWKWebViewController alloc] init];
webVC.webUrlString = info[@"clickData"];
webVC.needShowReload = YES;
webVC.shouldIncludeIdentifyInfo = YES;
[[UIViewController fus_topViewController].navigationController pushViewController:webVC animated:YES];
break;
}
default:
break;
}
[FUSHttpHelper postRequestBinaryWithUrl:FUSCommonURLs.fus_URL_UploadPushClickLog params:@{@"pushType":@(pushType),@"pushEventType":@(pushEventType)} success:nil failure:nil];
}
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token {
[GeTuiSdk registerDeviceTokenData:token];
NSString *driverToken = @"";
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13) {
if (![token isKindOfClass:[NSData class]]) {
//记录获取token失败的描述
return;
}
const unsigned *tokenBytes = (const unsigned *)[token bytes];
driverToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
}else{
driverToken = [[[[token description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
}
if (token) {
[[NSUserDefaults standardUserDefaults] setObject:token forKey:FUSChatUDKeys.fus_DEVICE_TOKEN_DATA];
}
if (![NSString isNull:driverToken]) {
[[NSUserDefaults standardUserDefaults] setObject:driverToken forKey:DEVICE_TOKEN_STRING];
}
}
#pragma mark 个推
/** SDK启动成功返回cid */
- (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
......@@ -205,9 +351,52 @@ static NSString *const kGtAppSecret = @"OSSSWqbWY0ACJiUv4AHdW7";
NSLog(@"%@", msg);
}
- (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification completionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
completionHandler( UNNotificationPresentationOptionBadge|
UNNotificationPresentationOptionSound|
UNNotificationPresentationOptionAlert);
}
- (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId{
- (void)GeTuiSdkDidReceiveNotification:(NSDictionary *)userInfo notificationCenter:(UNUserNotificationCenter *)center response:(UNNotificationResponse *)response fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
completionHandler(UIBackgroundFetchResultNoData);
}
- (void)GeTuiSdkDidReceiveSlience:(NSDictionary *)userInfo fromGetui:(BOOL)fromGetui offLine:(BOOL)offLine appId:(NSString *)appId taskId:(NSString *)taskId msgId:(NSString *)msgId fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) {
return;
}
// 如果收到离线消息后,马上点击进入App,个推的透传还会推多一条在线的过来,所以延迟1s,判断APP是否已经开启的状态,再决定要不要弹一个本地推送
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) {
return;
}
NSDictionary *payload = [userInfo[@"payload"] converToDictionary];
if ([NSDictionary isNull:payload] == NO) {
NSDictionary *data = payload[@"data"];
if ([NSDictionary isNull:data] == NO) {
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = data[@"title"];
content.subtitle = data[@"subtitle"];
content.body = data[@"text"];
content.sound = UNNotificationSound.defaultSound;
content.userInfo = @{@"transmissionContent":[payload converToString]};
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1 repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:msgId content:content trigger:trigger];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil];
}
}
});
completionHandler(UIBackgroundFetchResultNoData);
}
......@@ -241,75 +430,6 @@ static NSString *const kGtAppSecret = @"OSSSWqbWY0ACJiUv4AHdW7";
}
}
/// 开始跳转
- (void)fus_startJunmpIntoPage:(NSDictionary *)dict {
if ([NSDictionary isNull:dict]) {
return;
}
NSString *uid = [FUSCacheDataShare shareStore].userDetailInfo.uid;
if ([NSString isNull:uid]) {
return;
}
NSInteger type = [dict[@"type"] integerValue];
NSDictionary *dataDict = dict[@"data"];
[self fus_jumpIntoPageControllerWithType:type infor:dataDict];
}
- (void)fus_jumpIntoPageControllerWithType:(NSInteger)type infor:(NSDictionary *)info {
NSString *userid = [info[@"userId"] description];
// 关闭当前的弹窗
[FUSAlertView fus_dismissAllAlertViewWithAnimate:YES];
// 移除所有window层的弹窗
UIView *rootSuperViewBelowWindow = [UIApplication sharedApplication].keyWindow.rootViewController.view.superview;
while (rootSuperViewBelowWindow.superview
&& rootSuperViewBelowWindow.superview != [UIApplication sharedApplication].keyWindow) {
rootSuperViewBelowWindow = rootSuperViewBelowWindow.superview;
}
for (UIView *view in [UIApplication sharedApplication].keyWindow.subviews) {
if (view != rootSuperViewBelowWindow) {
[view removeFromSuperview];
}
}
switch (type) {
// 进入直播间
case 1: {
if ([NSString isNull:userid]) {
return;
}
if ([FUSCacheDataShare shareStore].userDetailInfo.uid && userid) {
// Firebase 统计
[FIRAnalytics logEventWithName:@"enterroom" parameters:@{@"source":@"push",
@"useruid":[FUSCacheDataShare shareStore].userDetailInfo.uid,
@"broadcasteruid":userid}];
}
[FUSRouter.liveRouter fus_enterLiveRoom:userid];
break;
}
// 进入单聊页面
case 3: {
if ([NSString isNull:userid]) {
return;
}
NSString *nickname = info[@"nickname"];
NSString *face = info[@"face"];
[FUSRouter.chatRouter fus_chatWithUser:userid nickname:nickname face:face];
break;
}
default:
break;
}
}
- (void)checkPasteboard {
NSString *localIcid = [[NSUserDefaults standardUserDefaults] objectForKey:OPENINSTALL_ICID];
......
......@@ -176,32 +176,21 @@
// 重置重试次数
_retryCount = 0;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *token = [[NSUserDefaults standardUserDefaults] objectForKey:FUSChatUDKeys.fus_DEVICE_TOKEN_DATA];
[[EMClient sharedClient] bindDeviceToken:token];
[[EMClient sharedClient] registerForRemoteNotificationsWithDeviceToken:token completion:^(EMError *aError) {
FUSLogInfo(@"");
}];
self.retryCount = 0;
// 设置离线推送
[[EMClient sharedClient].pushManager updatePushDisplayName:[FUSCacheDataShare shareStore].userDetailInfo.nickname];
[[EMClient sharedClient].pushManager updatePushDisplayStyle:EMPushDisplayStyleMessageSummary];
});
[self fus_bindAPNsToken];
} failure:^(NSString *errorMsg) {
// 重试次数加1
_retryCount ++;
self.retryCount ++;
if (_retryCount <= 3) { // 重试3次
if (self.retryCount <= 3) { // 重试3次
[self fus_autoLoginWithAccount:account];
}else{
// 重置重试次数
_retryCount = 0;
self.retryCount = 0;
dispatch_async(dispatch_get_main_queue(), ^{
// 更新到最新的离线会话
......@@ -211,6 +200,21 @@
}];
}
- (void)fus_bindAPNsToken {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *token = [[NSUserDefaults standardUserDefaults] objectForKey:FUSChatUDKeys.fus_DEVICE_TOKEN_DATA];
[[EMClient sharedClient] bindDeviceToken:token];
[[EMClient sharedClient] registerForRemoteNotificationsWithDeviceToken:token completion:^(EMError *aError) {
FUSLogInfo(@"");
}];
// 设置离线推送
[[EMClient sharedClient].pushManager updatePushDisplayName:[FUSCacheDataShare shareStore].userDetailInfo.nickname];
[[EMClient sharedClient].pushManager updatePushDisplayStyle:EMPushDisplayStyleMessageSummary];
});
}
- (void)fus_logOffWithSuccess:(void(^)(void))success failure:(void(^)(void))failure
{
__weak typeof(self) weakSelf = self;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment