通知
通知有助于便于粘粘用户,让用户实时了解动态内容。
推送
目前推送的第三方有很多,比如极光、个推等其他第三方推送,下面我们拿极光推送进行举例说明;
极光推送
APNs 通知
JPush 代理开发者的应用(需要开发者提供的应用证书),想苹果 APNs 服务器推送,再由 APNs Server 推送到 iOS 设备上进行展示相关样式的信息,开发者也可以根据 Apple 提供的接口自行开发。同时用户可以通过 “设置” -> “通知” 进行设置,开启或者关闭某个 App 的推送能力。
应用内消息
应用内推送,即 App 启动时,内嵌的 JPush SDK 会开启长链接到 JPush Server,从而 JPush Server 可以推送消息到 App 里。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| NSDictionary * userInfo = response.notification.request.content.userInfo;
UNNotificationRequest *request = response.notification.request; // 收到推送的请求 UNNotificationContent *content = request.content; // 收到推送的消息内容
NSNumber *badge = content.badge; // 推送消息的角标 NSString *body = content.body; // 推送消息体 UNNotificationSound *sound = content.sound; // 推送消息的声音 NSString *subtitle = content.subtitle; // 推送消息的副标题 NSString *title = content.title; // 推送消息的标题
if ([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [JPUSHService handleRemoteNotification:userInfo]; NSLog(@"iOS10 收到远程通知:%@", userInfo); } completionHandler();
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| // log NSSet with UTF8 // if not ,log will be \Uxxx - (NSString *)logDic:(NSDictionary *)dic { if (![dic count]) { return nil; } NSString *tempStr1 = [[dic description] stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"]; NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]; NSString *tempStr3 = [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""]; NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding]; NSString *str = [NSPropertyListSerialization propertyListFromData:tempData mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:NULL]; return str; }
|
1 2 3 4 5 6 7 8 9
| // 取得 APNs 标准信息内容 NSDictionary *aps = [userInfo valueForKey:@"aps"]; NSString *content = [aps valueForKey:@"alert"]; //推送显示的内容 NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge数量 NSString *sound = [aps valueForKey:@"sound"]; //播放的声音 // 取得Extras字段内容 NSString *customizeField1 = [userInfo valueForKey:@"customizeExtras"]; //服务端中Extras字段,key是自己定义的 NSLog(@"content =[%@], badge=[%d], sound=[%@], customize field =[%@]",content,badge,sound,customizeField1);
|