为什么push notification一直是object configurablee

推送那些事--证书制作
一、创建一个CSR,实现步骤如下:
创建一个证书请求
首先的首先,我们需要有一个证书签名请求文件,之后创建SSL证书才有意义。创建文件的方法如下:
1.在Mac上运行钥匙串访问(keychain)
2.选择钥匙串访问 & 证书助理
从证书颁发机构中请求一个证书
3.输入你的名字和邮件地址,CA邮件地址默认就可以,不要试图去进行任何改动。
4.选择“保存到硬盘”,这样就会将刚创建的证书请求文件下载到电脑桌面上了。
二、创建一个APP IDs,
实现步骤如下:
每个安装在你开发者设备上的iOS程序都需要一个独有的App
ID,方便起见,App
ID以反向路径规则命名,形如com.parseSampleApp,但是一定要注意App ID里不能包含星号("*")。创建步骤如下:
1.登陆网站Apple Developer Member
Center并进入iOS
Provisioning Portal。
2.从左边栏里点击App IDs。
3.选择New App ID,然后创建一个新的App
ID。一定要确保Bundle
Identifier一栏中没有星号。PetPlanetPush
4.将“Enable for Apple Push Notification
service”勾选上,continue,然后submit &》done
5.回到APP&
IDs中,发现刚才新建的PetPlanetPush中Push那一栏是Configurable,点击
在Push Notifications 中选择
Development&
SSl Certificate,点击Create
Certificate&continue &choose file ,选择在上一步操作中生成的CertificateSigningRequest.certSigningRequest
6.点击Generate开始生成,然后点击Download下载生成的SSL证书。
7.看到一个aps_development.cer表示操作成功
三、导出.p12文件
1.通过keychain程序来安装下载好的SSL证书。
2.接着在“我的证书”选项先面,找到你刚才安装名称形如“Apple Development IOS Push Services:
xxx”的证书。如果找不到的话就找到在前面创建好的aps_development.cer,然后keychain 里就会显示了。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。下次自动登录
现在的位置:
& 综合 & 正文
iPhone Apple Push Notification Service (APNS)
Apple’s has announced a push notification service for the iPhone that
it’ll provide to all developers. It’ll maintain a persistent IP
connection to the phone and let a 3rd party server ping Apple’s
notification service in order to push out notifications to users device,
which can be in the form of badges, sounds or custom textual alerts.
According to Apple, the service will preserve battery life and maintain
performance, not to mention work over WiFi or cellular.
What is Push Notification and How does it
Let’s say you’re running a 3rd party IM (instant message) client on
iPhone 2.0. When you exit the app, you no longer know if you’re
receiving more messages. (Sure, there are work around over SMS and
Email, but the app itself is dead to you).
With Apple’s Push Notification Service on iPhone OS 3.0, anytime
someone sends you a new IM, an alert can be sent from the IM
developer’s servers (yes, they’ll have to keep a session open for you on
their end), to Apple’s Push Notification Service (APNS) servers.
Apple’s PNS server will have a persistent TCP/IP connection to your
iPhone . Once Apple PNS gets the alert from the developer server, APNS
will “PUSH” it out to your iPhone 3.0.
Apple PNS currently supports 3 kinds of alerts: badges with a number
(like Mail uses to show you unread messages), custom sounds (like a beep
or bell or anything already built into the app by the developer), or
modal message boxes (like the kind that pop up to tell you your battery
is at 20%).
Apple isn’t making any promises on up-time for the service, and any
new service will have delays and downtime.
What APNS doesn’t solve, however, is the lack of good notifications
on the iPhone, and applications that require multitasking for something
other than notification (i.e. streaming internet radio apps).
Imagine if 10 apps try to push out 10 alerts at the same time, how
will Apple manage those on your device? Will you have to “cancel” or
“accept” 50 modal message dialogs, or be hit by a cacophony of 30 random
sounds? We don’t know yet, but hopefully Apple will address this.
Generate APNS SSL Certificate
To get started with APNS we need to generate an certificate unique to
each applications which will support APNS. We need to log into our
iPhone developer portal with “Team Agent” access.
Only users with “Team
Agent” access can do the below mentioned process. The iPhone developer
portal with “Team Agent ” has a detailed steps to generate an APNS
certificate. You should be able to see the screen shown below in the
portal to start creating your APNS certificate. Follow the steps
mentioned below:-
<img title="APNS
Development Certificate" src="/images/apns_development_certificate_request.jpg" alt="APNS Development Certificate" width="240" height="218">
Fig 1: APNS Development Certificate
(1) You need to create an App ID without .*
in the iPhone developer Portal. An App ID without .*
means its unique and works only for a single application
(2) Generate a certificate signing request from your Mac’s keychain
(You should be an Team Agent to have access to the wizard shown in
Figure 1) as shown in figure 2 and save
(3) Upload the CertificateSigningRequest.certSigningRequest to the
Program Portal
(4) Wait for the generation of cert (about 1 min). Download the
certificate (aps_developer_identity.cer) from the Program Portal
(5) Keep (or rename them if you want) these 2 files (steps 2 and 4)
in a safe place. You might need the
CertificateSigningRequest.certSigningRequest file to request a
production cert in the future or renew it again.
(6) Suppose you have imported the aps_developer_identity.cer to the
Then you have to export these new cert and the private key
of this cert (not the
public key) and saved as .p12 files.
(7) Then you use these commands to generate the cert and key in Mac’s
Terminal for PEM format (Privacy Enhanced Mail Security Certificate)
openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
openssl pkcs12 -nocerts -out key.pem -in key.p12
(8) The cert.pem and key.pem files will be used by your own program
communicating with APNS.
(9) If you want to remove the passphase of private key in key.pem, do
openssl rsa -in key.pem -out key.unencrypted.pem
Then combine the certificate and key
cat cert.pem key.unencrypted.pem & ck.pem
But please set the file permission of this unencrypted key by using chmod 400
and is only readable by
root in a sever configuration.
(10) The testing APNS is at ssl://gateway.sandbox.:2195
Fig 2: Request Certificate From Keychain Access
(11) For the source codes to push payload message to the APNS, you
can find them in the Developer Forum. This is the one that I used, for
php. Run this (after obtaining the device token from the testing device
and with iPhone Client program setup)php -f apns.php "My Message" 2
or if you put this php script and the ck.pem in a local web server,
you can use this to testhttp://127.0.0.1/apns/apns.php?message=Hello%20from%20macoscoders&badge=2&sound=received5.caf
$deviceToken =
'02da851dXXXXXXXXb4f2b5bfXXXXXXXXce198270XXXXXXXX0d3dac72bc87cd60';
masked for security reason
// Passphrase for the private key (ck.pem file)
// $pass = '';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or
$message = 'Message received from javacom';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];
// Construct the notification payload
$body = array();
$body['aps'] = array('alert' =& $message);
if ($badge)
$body['aps']['badge'] = $
if ($sound)
$body['aps']['sound'] = $
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert',
'ck.pem');
// assume the private key passphase was removed.
// stream_context_set_option($ctx, 'ssl', 'passphrase',
stream_socket_client('ssl://gateway.sandbox.:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstrn";
print "Connection OKn";
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace('
', '', $deviceToken)) . pack("n",strlen($payload)) . $
print "sending message :" . $payload . "n";
fwrite($fp, $msg);
fclose($fp);
(12) For iPhone Client Program, you need to edit the bundle
identifier to the App ID that you created and imported the new
provisioning profile for that APP ID to the XCode and iPhone. Then
implement the following methods in AppDelegate to Build & Go
AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication
*)application {
NSLog(@"Registering Remote Notications");
// For beta 2
[[UIApplication sharedApplication]
registerForRemoteNotifications];
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)]; // For beta 3
// other codes here
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"%@",[[[launchOptions
objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]
objectForKey:@"aps"] objectForKey:@"alert"]);
return YES;
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken: %@", deviceToken);
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Error in registration. Error: %@", error);
(13) Additional tips
- The feedback service is currently unavailable.
- Send your messages to gateway.sandbox.:2195 during the
beta period.
- Devices must be set up as new iPhones in iTunes in order to generate
device tokens. Restoring from backup is not currently supported.
-Make sure the audio file received5.caf is included in your
application resource.
(13a) Registering an App ID for Apple Push Notification service
1. In the App ID section of the Program Portal, locate the App ID you
wish to use with the Apple Push Notification service. Only App IDs with
a specific bundle ID can be used with the APNs. You cannot use a
“wild-card” application ID. You must see “Available” under the Apple
Push Notification service column to register this App ID and configure a
certificate for this App ID.
2. Click the ‘Configure’ link next to your desired App ID.
3. In the Configure App ID page, check the Enable Push Notification
Services box and click the Configure button. Clicking this button
launches the APNs Assistant, which guides you through the next series of
steps that create your App ID specific Client SSL certificate.
4. Download the Client SSL certificate file to your download
location. Navigate to that location and double-click the certificate
file (which has an extension of cer) to install it in your keychain.
5. When you are finished, click Done in the APNS Assistant.
6. Double-clicking the file launches Keychain Access. Make sure you
install the certificate in your login keychain on the computer you are
using for provider development. The APNs SSL certificate should be
installed on your notification server.
7. When you finish these steps you are returned to the Configure App
ID page of the iPhone Dev Center portal. The certificate should be
badged with a green circle and the label “Enabled”.
8. To complete the APNs set-up process, you will need to create a new
provisioning profile containing your APNs-enabled App ID.
About Me: Anish:
Mac OS X software development is my bread winner
with over 6 years of experience. Expertise in Color Management, TWAIN
Scanner drivers on Mac OS X, Photoshop Filter and
Import Plugin
development on Mac OS X, iPhone. As an hobby I love to work on PHP,
Flex, AIR, Photoshop. Check the 'About' page for more.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
&&&&推荐文章:
【上篇】【下篇】

我要回帖

更多关于 object configurable 的文章

 

随机推荐