(九十七)集成JPush实现远程通知和推送的发送
上节介绍了通过直接和APNS交互实现推送的方法,较为繁琐,最为重要的是发送推送需要特定的服务端,通过JPush,不仅可以简化客户端的接收,还可以通过控制台或者API实现通知的发送。
首先注册JPush,创建应用,需要传入p12交换证书,如果只是调试,传入开发证书即可,打开Keychain Access,点击左侧的login,右键点击Export,即可导出为p12,注意设置密码,在应用创建时有相应的地方填入证书密码。选择p12后即可完成应用的创建,点击应用可以看到App Key和Master Secret,App Key在客户端用的到,二者在服务端都用的到。
【客户端的集成】
①首先去JPush官网下载iOS SDK,将lib导入工程,并且导入下面这些框架:
这些框架必须导入,因为即使是高版本的Xcode也不能自动导入storyboard和静态库所需要的框架。
②新建一个plist,名为PushConfig.plist,在里面填写下面的内容:
注意APP_KEY填写创建的应用的KEY;CHANNEL指的是统计渠道,可以随意填写;第一项写0代表开发者证书,1代表生产证书。
不要忘记修改info.plist中的bundle identifier和创建应用时一致,也必须和推送证书一致。
③打开后台开关:
④在AppDelegate中用下面的代码来初始化,就可以接收消息了。
//
// AppDelegate.m
// 集成JPush
//
// Created by 11 on 7/30/15.
// Copyright (c) 2015 soulghost. All rights reserved.
// #import "AppDelegate.h"
#import "APService.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) { [APService registerForRemoteNotificationTypes:UIUserNotificationTypeBadge categories:nil]; }else{ [APService registerForRemoteNotificationTypes:UIUserNotificationTypeBadge categories:nil]; } [APService setupWithOption:launchOptions]; return YES;
} - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { // Required
[APService registerDeviceToken:deviceToken]; // JPush自动管理deviceToken。
} - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { // Required
[APService handleRemoteNotification:userInfo];
} - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { // IOS 7 Support Required
[APService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
} @end
【推送的发送】
有两种方式,一是通过控制台,二是通过API。
①控制台发送:
在控制台点击推送、发送通知,经过设置即可发送出去。
②利用API,这里以php为例,首先下载vendor.tar.gz到服务端,然后解压,新建一个php文件,写入如下内容:
注意引入vendor/autoload.php时的路径。
注意填写key和secret,然后修改消息体,即可实现发送不同内容。
<?php
require_once 'vendor/autoload.php';
use JPush\Model as M;
use JPush\JPushClient;
use JPush\Exception\APIConnectionException;
use JPush\Exception\APIRequestException; $br = '<br/>';
$app_key = '这里填写key';
$master_secret = '这里填写secret';
$client = new JPushClient($app_key, $master_secret); $result = $client->push()
->setPlatform(M\all)
->setAudience(M\all)
->setNotification(M\notification('Hi, JPush')) // 消息体
->send();
echo 'Push Success.' . $br;
echo 'sendno : ' . $result->sendno . $br;
echo 'msg_id : ' .$result->msg_id . $br;
echo 'Response JSON : ' . $result->json . $br;
?>
(九十七)集成JPush实现远程通知和推送的发送的更多相关文章
- IOS之推送通知(本地推送和远程推送)
推送通知和NSNotification是有区别的: NSNotification:是看不到的 推送通知:是可以看到的 IOS中提供了两种推送通知 本地推送通知:(Local Notification) ...
- 极光推送Jpush(v3)服务端PHP版本集成(V3版本只调用推送API)
因为版本升级,极光推送的API也有了V3,功能也更丰富了,但是对于我们有的用户来说,我们还是只需要调用推送的API就够了. 下载了一份PHP服务端的SDK(下载地址:http://docs.jpush ...
- 1.NSNotification|远程通知|本地通知|激光推送
1. 通知在iOS中应用非常广泛,合理的应用通知可以减少冗余代码,使我们的代码层次结构变了更加的清晰明了,利于程序猿读写.它主要分为不可见通知可见通知两种: 1.1 不可见通知,主要是有系统发出的 ...
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
在VisualStudio2010中新建网站JPushAndroid.添加引用json帮助类库Newtonsoft.Json.dll. 在web.config增加appkey和mastersecret ...
- iOS 通知、本地通知和推送通知有什么区别? APNS机制。
本地/推送通知为不同的需要而设计.本地通知对于iPhone,iPad或iPod来说是本地的.而推送通知——来自于设备外部.它们来自远程服务器——也叫做远程通知——推送给设备上的应用程序(使用APNs) ...
- JPush Flutter Plugin(Futter推送-极光推送)
https://pub.flutter-io.cn/packages/jpush_flutter JPush's officially supported Flutter plugin (Androi ...
- Git:创建远程仓库并推送内容到远程库
1.添加远程仓库 1.1点击该按钮创建一个新仓库 2.推送到远程仓库 2.1根据GitHub的提示,在本地的learngit仓库下运行命令git remote add origin https://g ...
- 四、 git关联远程仓库及推送
接之前笔记,在 github上建立与本地同名的仓库 demo 关联远程仓库 1. https 模式 远程库的名字就是origin,这是Git默认的叫法 git remote add origi ...
- git创建远程分支并推送
1.查看所有分支(-a=>'查看全部的分支') git branch -a 2.创建本地test分支 git branch test 2.2切换test分支 git checkout test ...
随机推荐
- Codeforces Round #419 D. Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition an ...
- 【POJ 1459 power network】
不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...
- hdu 5573Binary Tree
Binary Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- bzoj1044[HAOI2008]木棍分割 单调队列优化dp
1044: [HAOI2008]木棍分割 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4314 Solved: 1664[Submit][Stat ...
- 去掉textarea和input在ios下默认出现的圆角
-webkit-appearance:none;/*清除ios默认圆角*/ border-radius:0;
- 关于npm run build 报错解决方案
# 特定的错误 ERROR in statics/mobile/js/vendor.cef13a0e680a5bc0d8b3.js from UglifyJsUnexpected token: pun ...
- RabbitMQ日志无法禁用问题
最近使用spring+rabbitmq发现其Debug日志非常多,几天就把服务器磁盘弄爆了. 原来rabbitmq依赖logback.xml输出日志. 在和log4j.properties同目录下加一 ...
- 58. Length of Last Word(easy, 字符串问题)
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 有趣的冷知识:编程中Foo, Bar 到底什么意思?
转自:编程中Foo, Bar 到底什么意思? 1 前言 在很多国外计算机书本和一些第三份开源软件的Demo中经常用到两个英文单词Foo,Bar.这到底是什么意思呢?从步入屌丝界的IT生活见到这两个单词 ...
- Flume 读取RabbitMq消息队列消息,并将消息写入kafka
首先是关于flume的基础介绍 组件名称 功能介绍 Agent代理 使用JVM 运行Flume.每台机器运行一个agent,但是可以在一个agent中包含多个sources和sinks. Client ...