-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjpush-ios-pei-zhi-guo-cheng.html
177 lines (164 loc) · 7.27 KB
/
jpush-ios-pei-zhi-guo-cheng.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="./jpush-ios-pei-zhi-guo-cheng.html" />
<title> 愚钝的故事 — JPush ios 配置过程
</title>
<link rel="stylesheet" href="./theme/css/style.css">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<meta name="author" content="Jet Geng">
<meta name="description" content="ios推送">
<meta name="tags" contents="ios, push, ">
</head>
<body>
<header class="header">
<div class="container">
<div class="header-inner">
<h1 class="header-name">
<a class="nodec" href="/">愚钝的故事</a>
</h1>
<h3 class="header-text">Jet Geng的工作和生活</h3>
<ul class="header-menu list-inline">
<li><a class="nodec icon-github" href="https://github.com/jetgeng"></a></li>
</ul>
</div>
</div>
</header> <!-- /.header --> <div class="container">
<div class="post full-post">
<h1 class="post-title">
<a href="/jpush-ios-pei-zhi-guo-cheng.html" title="Permalink to JPush ios 配置过程">JPush ios 配置过程</a>
</h1>
<ul class="list-inline">
<li class="post-date">
<a class="text-muted" href="/jpush-ios-pei-zhi-guo-cheng.html" title="2015-03-31T10:20:00+08:00">Tue 31 March 2015</a>
</li>
<li class="muted">·</li>
<li class="post-category">
<a href="./category/she-ji.html">设计</a>
</li>
<li class="muted">·</li>
<li>
<a href="/tag/ios.html">ios</a>, <a href="/tag/push.html">push</a> </li>
<li class="muted">·</li>
<li>
<address class="post-author">
By <a href="./author/jet-geng.html">Jet Geng</a>
</address>
</li>
</ul>
<div class="post-content">
<div class="section" id="id1">
<h2>准备条件</h2>
<p>JPush推送本质上还是使用的apple的apn服务。 所以apn所需要的所有东西,他都需要。比如证书之类的。
而且这一部分在网上已经有很完毕的描述了。我简单的列举一下我读过的一些东西。</p>
<blockquote>
<ol class="arabic simple">
<li><a class="reference external" href="http://blog.csdn.net/showhilllee/article/details/8631734">一步一步教你做ios推送</a></li>
<li><a class="reference external" href="http://tanqisen.github.io/blog/2013/02/27/ios-push-apns/">一步一步实现iOS应用PUSH功能</a></li>
</ol>
</blockquote>
<p>通过阅读以上的文章确认我们需要的内容如下:</p>
<ol class="arabic simple">
<li>在苹果开发者账户中生成 appid。</li>
<li>在苹果开发者中心生成对应环境的推送证书。</li>
<li>下载证书,导出成p12文件。</li>
<li>上传证书到jpush平台。</li>
<li>把jpush的 phone-gap。 <a class="reference external" href="https://github.com/jpush/jpush-phonegap-plugin">https://github.com/jpush/jpush-phonegap-plugin</a> 插件加入到项目中</li>
</ol>
</div>
<div class="section" id="id2">
<h2>开始干活</h2>
<p>生成证书的之类的具体操作就不多说了。只是把我遇到的坑说出来。这样大家就可以不用重复我踩过的坑了。</p>
<div class="section" id="id3">
<h3>安装证书 -- 第一个坑</h3>
<p>下载完在苹果开发者中心的证书,大家都说通过 <strong>双击</strong> 来安装到 Mac 上的钥匙串程序中。这里我没有能够安装成功。
我的解决办法是在钥匙串中选中 <strong>登陆</strong> , 从Finder中将证书拖拽到钥匙串中。</p>
</div>
<div class="section" id="jpush">
<h3>上传证书到JPush平台</h3>
<p>这个问题折腾了很久。在上传证书的时候有两点需要注意:</p>
<ol class="arabic simple">
<li>如果导出的时候设定密码了。密码一定要填写。</li>
<li>注意测试环境和生产环境证书不一样</li>
<li>导出证书的时候选中证书就是下面图中方块选中的部分,而不是下面的秘钥。如下图所示:</li>
</ol>
<div class="figure">
<img alt="" src="../images/ios_zhengshu.png" />
</div>
</div>
<div class="section" id="ionic">
<h3>修改ionic项目</h3>
<p>这个地方我不得不吐槽一下,理论上只需要使用 <strong>ionic add plugin jpush</strong> 这样就可以完成安装动作。
但是jpush现在不行。那就先手动改吧!</p>
<p>需要修改的文章有两个,一个是 PushConfig.plist.
写入两个值:</p>
<dl class="docutils">
<dt>APP_KEY</dt>
<dd>在JPush中的appKey。</dd>
<dt>CHANNEL</dt>
<dd>这个值只是用来统计的。可以根据公司的规则设定。不影响发送功能。</dd>
</dl>
<p>修改AppDelegate.m 这个文件</p>
<p>在文件开始加入导入:</p>
<div class="highlight"><pre><span></span>import "APService.h"
import "JPushPlugin.h"
</pre></div>
<p>其他地方按照 <a class="reference external" href="https://github.com/jpush/jpush-phonegap-plugin">https://github.com/jpush/jpush-phonegap-plugin</a> IOS手工安装 这个地方就可以了。千万不要按照 <strong>IOS使用PhoneGap/Cordova CLI自动安装</strong> 中的修改文件的方法修改。他的那个</p>
<div class="highlight"><pre><span></span>- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required
[APService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName: kJPushPluginReceiveNotification
//这个 kJPushPluginReceiveNotification 是错误的,没有定义。 要将这一句去掉。
object:userInfo];
}
</pre></div>
</div>
</div>
</div>
</div>
<hr class="separator">
<div class="col-md-8 col-md-offset-2">
<div id="disqus_thread">
<script>
var disqus_shortname = 'techfoolishstory';
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>
Please enable JavaScript to view the
<a href="https://disqus.com/?ref_noscript=techfoolishstory">
comments powered by Disqus.
</a>
</noscript>
<a href="https://disqus.com" class="dsq-brlink">
blog comments powered by <span class="logo-disqus">Disqus</span>
</a>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="text-center">
Jet Geng, <a href="" target="_blank">版权归Jet Geng所有,转载请注明!</a> unless otherwise noted.
</p>
<div class="text-center">
Generated by <a href="http://getpelican.com" target="_blank">Pelican</a> with the <a href="http://github.com/nairobilug/pelican-alchemy">alchemy</a> theme.
</div>
</div>
</footer> <!-- /.footer -->
<script src="./theme/js/jquery.min.js"></script>
<script src="./theme/js/bootstrap.min.js"></script>
</body> <!-- 42 -->
</html>