第一步,在Gemfile里添加
gem ' jpush-api-ruby-client'
gem 'rest-client'
gem 'json'
第二步,下载jpush的sdk,添加到客户端的代码中,并进行配置。
在Build Settings 里搜索Search关键字,然后找到Library Search Paths,将lib文件的路径写进去。
第三步,APService设置
//设置推送类型
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
//初始化APService
[APService setupWithOption:launchOptions];
//接到非APNS推送时的回调
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkDidReceiveMessage:) name:kAPNetworkDidReceiveMessageNotification object:nil];
//接到非APNS通知的时候将通知上传到jpush服务器
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[APService handleRemoteNotification:userInfo];
}
//在获取设备deviceToken的回调里将devoiceToken上传到jpush服务器
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[APService registerDeviceToken:deviceToken];
}
第四步、服务端代码的编写
app_key = '3b1c94e4c........' //在你的jpush注册的app当中
master_secret = '09520a3e9.......' //在你的jpush注册的app当中
time_to_live = 60 * 60 * 24//存活时间
jpush_client = JPushApiRubyClient::Client.new(app_key, master_secret, 'platform' => JPushApiRubyClient::PlatformType::IOS)//针对ios平台
send_no = jpush_client.generate_send_no //生成一个通知
msg_title = '通知'
msg_content = message_content
//以别名的方式进行发送
puts send_result = jpush_client.send_notification_with_alias(send_no,friend, msg_title, msg_content)
发送方式解释:
tag和alias的解释
alias下面可以有很多的tag这样我们能够批量发送通知。
详细见
https://github.com/jpush/jpush-api-ruby-client/blob/master/example/client_example.rb
http://docs.jpush.cn/display/dev/API%3A+iOS