用OC写的极光推送服务端代码
来源:互联网 发布:增删算法统宗拍卖 编辑:程序博客网 时间:2024/05/16 01:17
用OC写的极光推送服务端代码
极光推送 - 服务端代码API:http://docs.jpush.io/server/rest_api_v3_push/#_5
OC这样写
- (void)testPush {
NSString*keys = @"0cd0edeb61e54d93459f6513:1c84a3fae6c9f8375c341998g"; //me
// NSString *keys = @"bc0cca8452b6e2082c5e793c:9525b4edae9c87cd536e07ef"; //qk
NSData *nsdata = [keys dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0];
LHSessionManager *lhmanager = [LHSessionManagermanager];
base64Encoded = [NSStringstringWithFormat:@"Basic %@", base64Encoded];
lhmanager.requestSerializer= [AFJSONRequestSerializerserializer];//申明请求的数据是json类型
NSData *nsdata = [keys dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0];
LHSessionManager *lhmanager = [LHSessionManagermanager];
base64Encoded = [NSStringstringWithFormat:@"Basic %@", base64Encoded];
lhmanager.requestSerializer= [AFJSONRequestSerializerserializer];//申明请求的数据是json类型
//返回参数无需设置,AFN默认就是json
// lhmanager.responseSerializer = [AFJSONResponseSerializer serializer];//申明返回的结果是json类型
[lhmanager.requestSerializersetValue:@"application/json"forHTTPHeaderField:@"Content-Type"];
//获取用户token
[lhmanager.requestSerializersetValue:@"/v3/push HTTP/1.1"forHTTPHeaderField:@"POST"];
[lhmanager.requestSerializersetValue:base64EncodedforHTTPHeaderField:@"Authorization"];
NSMutableDictionary *androidMsg = [[NSMutableDictionaryalloc]init];
[androidMsg setValue:@"Android端请注意,推送来了!" forKey:@"alert"];
[androidMsg setValue:@"Send to Android" forKey:@"title"];
[androidMsg setValue:@"1" forKey:@"builder_id"];
[androidMsg setValue:@{@"newsid":@"321"} forKey:@"extras"];
NSMutableDictionary *iosMsg = [[NSMutableDictionaryalloc]init];
[iosMsg setValue:@"IOS端请注意,推送来了!" forKey:@"alert"];
[iosMsg setValue:@"default" forKey:@"sound"];
[iosMsg setValue:@"+1" forKey:@"badge"];
[iosMsg setValue:@{@"newsid":@"321"} forKey:@"extras"];
NSMutableDictionary *notificationParams = [[NSMutableDictionaryalloc]init];
[notificationParams setValue:androidMsg forKey:@"android"];
[notificationParams setValue:iosMsg forKey:@"ios"];
// NSMutableDictionary *messageParams = [[NSMutableDictionary alloc] init];
// [messageParams setValue:@"注意,推送来了" forKey:@"msg_content"];
// [messageParams setValue:@"text" forKey:@"content_type"];
// [messageParams setValue:@"msg" forKey:@"title"];
// [messageParams setValue:@{@"key": @"value"} forKey:@"extras"];
//
// NSMutableDictionary *smsMsgParams = [[NSMutableDictionary alloc] init];
// [smsMsgParams setValue:@"sms msg content" forKey:@"content"];
// [smsMsgParams setValue:@"3600" forKey:@"delay_time"];
NSMutableDictionary *optionsParams = [[NSMutableDictionaryalloc]init];
[optionsParams setValue:@"60" forKey:@"time_to_live"];
[optionsParams setValue:@"false" forKey:@"apns_production"];
NSDictionary *dic = [NSDictionarydictionaryWithObjectsAndKeys:
@[@"android",@"ios"],@"platform",
@"all",@"audience",
notificationParams, @"notification",
// messageParams, @"message",
// smsMsgParams, @"sms_message",
optionsParams, @"options",
nil];
[lhmanager POST:@"https://api.jpush.cn/v3/push"parameters:dicprogress:^(NSProgress*_Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask*_Nonnull task, id _NullableresponseObject) {
NSLog(@"推送成功\n\nresponseObject = %@", responseObject);
} failure:^(NSURLSessionDataTask*_Nullable task, NSError * _Nonnull error) {
NSLog(@"失败%@", error);
}];
//获取用户token
[lhmanager.requestSerializersetValue:@"/v3/push HTTP/1.1"forHTTPHeaderField:@"POST"];
[lhmanager.requestSerializersetValue:base64EncodedforHTTPHeaderField:@"Authorization"];
NSMutableDictionary *androidMsg = [[NSMutableDictionaryalloc]init];
[androidMsg setValue:@"Android端请注意,推送来了!" forKey:@"alert"];
[androidMsg setValue:@"Send to Android" forKey:@"title"];
[androidMsg setValue:@"1" forKey:@"builder_id"];
[androidMsg setValue:@{@"newsid":@"321"} forKey:@"extras"];
NSMutableDictionary *iosMsg = [[NSMutableDictionaryalloc]init];
[iosMsg setValue:@"IOS端请注意,推送来了!" forKey:@"alert"];
[iosMsg setValue:@"default" forKey:@"sound"];
[iosMsg setValue:@"+1" forKey:@"badge"];
[iosMsg setValue:@{@"newsid":@"321"} forKey:@"extras"];
NSMutableDictionary *notificationParams = [[NSMutableDictionaryalloc]init];
[notificationParams setValue:androidMsg forKey:@"android"];
[notificationParams setValue:iosMsg forKey:@"ios"];
// NSMutableDictionary *messageParams = [[NSMutableDictionary alloc] init];
// [messageParams setValue:@"注意,推送来了" forKey:@"msg_content"];
// [messageParams setValue:@"text" forKey:@"content_type"];
// [messageParams setValue:@"msg" forKey:@"title"];
// [messageParams setValue:@{@"key": @"value"} forKey:@"extras"];
//
// NSMutableDictionary *smsMsgParams = [[NSMutableDictionary alloc] init];
// [smsMsgParams setValue:@"sms msg content" forKey:@"content"];
// [smsMsgParams setValue:@"3600" forKey:@"delay_time"];
NSMutableDictionary *optionsParams = [[NSMutableDictionaryalloc]init];
[optionsParams setValue:@"60" forKey:@"time_to_live"];
[optionsParams setValue:@"false" forKey:@"apns_production"];
NSDictionary *dic = [NSDictionarydictionaryWithObjectsAndKeys:
@[@"android",@"ios"],@"platform",
@"all",@"audience",
notificationParams, @"notification",
// messageParams, @"message",
// smsMsgParams, @"sms_message",
optionsParams, @"options",
nil];
[lhmanager POST:@"https://api.jpush.cn/v3/push"parameters:dicprogress:^(NSProgress*_Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask*_Nonnull task, id _NullableresponseObject) {
NSLog(@"推送成功\n\nresponseObject = %@", responseObject);
} failure:^(NSURLSessionDataTask*_Nullable task, NSError * _Nonnull error) {
NSLog(@"失败%@", error);
}];
}
写了个Demo,方便测试。
源码下载地址:http://download.csdn.net/detail/luohancc/9568727
1 0
- 用OC写的极光推送服务端代码
- 用Java写极光推送服务端代码和出现的问题
- 关于极光推送C#服务端代码的一些问题
- 极光推送JPush java服务端代码
- java服务端极光推送消息的集成
- 服务端极光推送
- 极光推送java服务端
- 极光推送java服务端
- 极光推送服务端实现
- 极光推送服务端开发
- 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)
- 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)
- 极光推送服务端开发(Jee)
- java服务端极光推送一
- IOS-OC-极光推送总结
- 服务端:极光推送之单人推送
- 极光推送服务器端 代码
- 极光推送C#代码
- CentOS 6.5 下 Tengine 安装记录
- 2 zip
- 古今言殊——《语文常谈》读书笔记(6)
- 老狼视频资源
- 获取屏幕scale
- 用OC写的极光推送服务端代码
- Android开发之TextView中间设置横线,适用于电商项目,商品原价之类的功能。
- Android studio导入常见问题
- MultipeerConnectivity框架,近场通信的基本使用
- ArcEngine GP笔记(持续补充中......)
- 添加过滤器后登录页面样式消失的问题
- 用java实现对MongoDB的基本操作(增删改查)
- Spring事务超时时间可能存在的错误认识
- iOS学习之——layout机制相关方法