原文地址:http://blog.sina.com.cn/s/blog_7bfb9660010144j6.html
以开发一个"MobileCAP"app为例
Step 1:Create cert request file。(当你在apple web site "provisioningportal"里生成"Development Certificate" 和 "Push SSLCertificate"时就会用到它)
1. Access "keychain access" by selecting"Application > Utilities >keychain access"
2. select menu "keychain access >certificate assistant > request certificate from acertificate authority"
3. set "User Email Address"as
4. set “Save the file” as“MobileCAP.certSigningRequest”.
当完成step1后,就会在Keychain Access的“Keys” section里生成了name为"MobileCAP"的public keyand private key pair
Step 2:export "MobileCAP" private key to a ".p12" file(该文件会在后面生成apns provider的.p12 or .pemfile时用到)
1. right click "MobileCAP“ private key and select "ExportMobileCAP..."2.
3. 这时会让你输入2次用于加密该.p12 file的密码,例如用"123456",接着会要求你输入一次your macaccount password
Step 3:Generate a "development certificate" file and downloadit
注意:"developmentcertificate"是与developer account对应的,即一个developeraccount只能生成一个"development certificate"。如果你之前已经创建过该cert, then justdownload it
1. 在apple web site "provisioning portal >Certificates" page, click "requestcertificate" button
2. 然后选定step 1生成的cert request file"MobileCAP.certSigningRequest"
3. follow the wizard, 就会生成一个cert file"ios_development.cer" file, andthen
Step 4:创建Registered device (这是把你要进行调试app的device添加到apple web site"provisioning portal > Devices"page,若你要在真机上调试app,这步是必须的,另外在后面创建provisioningprofile时要把该device包含进去,否则无法在该device上调试)
1. 在apple web site "provisioning portal >Devices" page, click "Add Device"button
2. 输入device name (任意名字)and device id(把你的device连接到电脑后,在iTunes可以查到device id)
Step 5:Create App ID (若你要在真机上调试app,这步是必须的,另外它会在后面创建provisioningprofile时用到,每个provisioning profile只对应一个app ID)
关于App ID和你创建的project的product name,company identifier的关系参看
AppID是开发和预配置系统的重要组件。这个唯一的ID允许应用程序与Apple PushNotification服务以及与外部硬件附件通信。AppID也可以用于在一组应用程序内共享密钥链数据,比如密码。另外它还用于configurationdata between your applications using iCloud
任何单个应用程序ID都是由包种子(bundle seed)ID和包标识符(bundleidentifier)组成的。包种子ID是由10个字符组成的唯一字符串。这个ID也可用于在利用单个应用程序ID构建的多个应用程序之间共享密钥链访问,还可以把这个ID合并到你可能希望用其扩展iPhone应用程序的多种硬件附件中。
包标识符可以是唯一的应用程序名称,或如果你想使用通配符包ID,则它也可以是星号(*)。当你想为多个应用程序使用单个应用程序ID时,这会很有用。例如,在开发原型时,我使用了名为“test”的应用程序ID,它为其包ID使用了一个星号。在我的iPod和iPhone上安装的所有开发构建软件上都使用这一个ID。要注意的一件事情是:只有使用显式的应用程序ID,才能使用ApplePush Notifications。
1.
2. 输入"Description" (任意取),“BundleIdentifier (App ID Suffix)” 为 "edu.cityu.MobileCAP","Bundle Seed ID (App ID Prefix)"的值是固定用上了TeamID
3. click Submit button
Step6:
注意:若你生成provisioningprofile时没有enable apns,而当你之后enable apns时,就要delete旧的provisioningprofile,然后生成一个新的。否则当你运行带apns feature的app时不会弹出notification allow ordeny 提醒窗口,但也不见有任何错误信息,总之就是用不到push notification!
1.
2.
3. 在弹出的"ApplePush Notification service SSL CertificateAssistant"窗口里,选定step 1创建的cert request file,followthe wizard,就会生成一个apns cert file named "aps_development.cer"
4. download the cert file
5. 这时你会在apple web site "provisioning portal> App IDs" page看到,你的这个App ID 在"pushnotification"这个column里是“Enabled forDevelopment”
Step7:
1.
2. 输入"Profile Name" (任意取)
3. 选择该profile要包含的certificates (可以包含多个)
4. 选择该profile要包含的App ID (只能选择一个)
5. 选择能够用来真机调试的devices (最好全选)
6. click submit button
7. download the provisioning profile file (extension is".mobileprovision")
- //
Let the device know we want to receive push notifications - [[UIApplication
sharedApplication] registerForRemoteNotific ationTypes: -
(UIRemoteNotificationType Badge | UIRemoteNotificationType Sound | UIRemoteNotificationType Alert)];
3.
- -
(void)application:(UIApplication*)application didRegisterForRemoteNoti ficationsWithDeviceToken :(NSData*)deviceToken - {
-
NSLog(@"My token is: %@", deviceToken); - }
-
- -
(void)application:(UIApplication*)application didFailToRegisterForRemo teNotificationsWithError :(NSError*)error - {
-
NSLog(@"Failed to get token, error: %@", error); - }
4. 运行该app in real device ( simulator doesn't support pushnotification)。这时你会在device上看到一个popup window(该窗口只会出现一次,重装app不会再出现),提示你该app会send pushnotification给你,如果同意则click OK,不同意则click " Nowallow”。如果选择了OK,那么在" Setting >Notifications“里会有你的app在list里。而且这时你的Xcode outputconsole会显示你的device token。
- Trying
17.172.233.65... - Connected
to gateway.sandbox.push-apple.com.akadns.net. - Escape
character is '^]'.
Press Ctrl+C to close the connection.
- openssl
s_client -connect gateway.sandbox.push.apple.com:2195 -cert MobileCAPCert.pem -key MobileCAPKey.pem
执行过程中会要你输入MobileCAPKey.pem生成时设置的密码。如果connectserver成功,就会等待你输入字串,你可以输入任意字串,然后回车,就会disconnect
注意:实际上有2个APNS servers: the “sandbox” server (用于testing) the liveserver(用于production mode)。我们这里测试的是sandbox server。live apnsserver的操作类似。
Step13
1. Download
2. 去掉SimplePush
3.修改simplepush.php
// Put your device tokenhere (without spaces):
//device token来自Step10的第4点,在outputconsole获取,注意:要去掉前后的尖括号,和中间的所有空格
$deviceToken
// Put your private key'spassphrase here:
//该值是step11.3生成MobileCAPKey.pem时设置的密码
$passphrase
// Put your alert messagehere:
$message
//.....
stream_context_set_option($ctx,'ssl', 'local_cert', 'MobileCAPCK.pem');
4. 在terminal window里,go to the simplepushfolder,然后执行下列命令,你的iPhone应该会收到一条push message。
注意:如果你的app在iphone里是正在运行,而且app是在frontend时,当它收到push message时是不会出现在iPhone顶部的notificationarea的!
Step14
step14.1. open "keychainaccess",然后找到"login > MyCertificates > Apple Development IOS Push Services:xxxx" cert
step14.2. right click this cert, and select"Export xxx......" to save as .p12 format (e.g.MobileCAPCK_For_CSharp.p12),过程中会要你输入保护该cert的密码
step14.3. 下载apns-shary,解压后,double click "JdSoft.Apple.Apns.sln" to opentheproject。然后我们只需要"JdSoft.Apple.Apns.Notifications"和"JdSoft.Apple.Apns.Notifications.Test",其他的都可以删掉。Rightclick "JdSoft.Apple.Apns.Notifications.Test",select "Set as Startup Project"
step14.4
step14.5
- //Put
your device token in here - string
testDeviceToken = "fe58fc8f527c363d1b775dca 133e04bff24dc5032d088369 92395cc56bfa62ef"; -
- //Put
your PKCS12 .p12 or .pfx filename here. - //
Assumes it is in the same directory as your app - string
p12File = "apn_developer_identity.p12"; -
- //This
is the password that you protected your p12File - //
If you did not use a password, set it as null or an empty string - string
p12FilePassword = "yourpassword";
Step 14.7 把APNS-SHARP移植到web project里
1. In visual studio, create a new "website"
2.
2. right click the web site root node,select
3. right click "App_Code" node, select "new folder", foldername任取。然后把APNS-SHARP libray"JdSoft.Apple.Apns.Notifications"目录里的所有.cs文件copy到该新建目录下。
4.把step14.2生成的MobileCAPCK_For_CSharp.p12
5. 然后把APNS-SHARP libray"JdSoft.Apple.Apns.Notifications.Test"目录里的Program.cs里代码适当改下,然后复制到Default.aspx.cs里(记得要importJdSoft.Apple.Apns.Notifications),就做成一个最简单的asp.netpush notification web site.
参考文档:
iphone在真机测试
http://www.cocoachina.com/bbs/read.php?tid=68636
http://hi.baidu.com/zhaodingfeng/blog/item/381b7e54025cab42564e00fa
在真机测试其实最终是体现在xcode > window >organizer里,打开organizer窗口后,最顶有个"Documentation",查看organization的帮助文档
apns
http://www.cnblogs.com/zhuqil/archive/2011/06/05/2070679.html
http://wsqwsq000.iteye.com/blog/1404282
http://blog.csdn.net/kmyhy/article/details/6688370