以开发一个"MobileCAP" app为例


Step 1: Create cert request file。(当你在apple web site "provisioning portal"里生成"Development Certificate" 和 "Push SSL Certificate"时就会用到它

1. Access "keychain access" by selecting "Application > Utilities > keychain access"

2. select menu "keychain access > certificate assistant > request certificate from a certificate authority"

3. set "User Email Address" as the same email address that you used to sign up for the iOS Developer Program, and set "Common Name" as "MobileCAP", leave "CA Email address" empty, and tick "Save to disk" option, click Continue button

4. set “Save the file” as “MobileCAP.certSigningRequest”.

当完成step 1后,就会在Keychain Access的“Keys” section里生成了name为"MobileCAP"的public key and private key pair

在Step 1过程中,有可能出error ''The specified item could not be found in the keychain"。解决方法是:restart keychain tool, and then 在keychain tool里,不要选择"keys" item,应该选择"all items",and then try again! (make sure you see "Let me specify key pair information" option in first wizard window, if you can't see it, may still fail)

参考链接 http://blog.csdn.net/totogogo/article/details/18632211


Step 2: export "MobileCAP" private key to a ".p12" file(该文件会在后面生成apns provider的.p12 or .pem file时用到)

1. right click "MobileCAP“ private key and select "Export MobileCAP..."

2. Save the private key as “MobileCAPKey.p12” file, click Save button

3. 这时会让你输入2次用于加密该.p12 file的密码,例如用"123456",接着会要求你输入一次your mac account password

Step 3: Generate a "development certificate" file and download it (会生成一个cert file,该cert会被import to keychain access里,若你要在真机上调试app,这步是必须的,另外该development certificate会在后面创建provisioning profile时用到)

注意:"development certificate"是与developer account对应的,即一个developer account只能生成一个"development certificate"。如果你之前已经创建过该cert, then just download it

1. 在apple web site "provisioning portal > Certificates" page, click "request certificate" button

2. 然后选定step 1生成的cert request file "MobileCAP.certSigningRequest"

3. follow the wizard, 就会生成一个cert file "ios_development.cer" file, and then click the "download" link to download it

Step 4: 创建Registered device (这是把你要进行调试app的device添加到apple web site "provisioning portal > Devices" page,若你要在真机上调试app,这步是必须的,另外在后面创建provisioning profile时要把该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,这步是必须的,另外它会在后面创建provisioning profile时用到,每个provisioning profile只对应一个app ID)

关于App ID和你创建的project的product name, company identifier的关系参看 http://blog.csdn.net/totogogo/article/details/7377870

App ID是开发和预配置系统的重要组件。这个唯一的ID允许应用程序与Apple Push Notification服务以及与外部硬件附件通信。App ID也可以用于在一组应用程序内共享密钥链数据,比如密码。另外它还用于configuration data between your applications using iCloud

任何单个应用程序ID都是由包种子(bundle seed)ID和包标识符(bundle identifier)组成的。包种子ID是由10个字符组成的唯一字符串。这个ID也可用于在利用单个应用程序ID构建的多个应用程序之间共享密钥链访问,还可以把这个ID合并到你可能希望用其扩展iPhone应用程序的多种硬件附件中。

包标识符可以是唯一的应用程序名称,或如果你想使用通配符包ID,则它也可以是星号(*)。当你想为多个应用程序使用单个应用程序ID时,这会很有用。例如,在开发原型时,我使用了名为“test”的应用程序ID,它为其包ID使用了一个星号。在我的iPod和iPhone上安装的所有开发构建软件上都使用这一个ID。要注意的一件事情是:只有使用显式的应用程序ID,才能使用Apple Push Notifications。

1.  在apple web site "provisioning portal > App IDs" page, click "new app ID" button

2. 输入"Description" (任意取),“Bundle Identifier (App ID Suffix)” 为 "edu.cityu.MobileCAP", "Bundle Seed ID (App ID Prefix)"的值是固定用上了Team ID

3. click Submit button

Step 6: Enable APNS in the App ID created by step 5, generate apns cert file and download it (若你的app要带push notification功能,这步是必须的。)

注意:若你生成provisioning profile时没有enable apns,而当你之后enable apns时,就要delete旧的provisioning profile,然后生成一个新的。否则当你运行带apns feature的app时不会弹出notification allow or deny 提醒窗口,但也不见有任何错误信息,总之就是用不到push notification!


1.  在apple web site "provisioning portal > App IDs" page, click "configure" link of the App ID created by step 5

2.  tick "Enable for Apple Push Notification service" option, and then click "configure" button of "Development Push SSL Certificate"

3. 在弹出的"Apple Push Notification service SSL Certificate Assistant"窗口里,选定step 1创建的cert request file,follow the wizard,就会生成一个apns cert file named "aps_development.cer"

4. download the cert file

5. 这时你会在apple web site "provisioning portal > App IDs" page看到,你的这个App ID 在"push notification"这个column里是“Enabled for Development

Step 7: create Provisioning Profile, download the file and add it to your device (若你要在真机上调试app,这步是必须的,Provision Profile实际上才是真正真机上需要添加的东东,没有它,无法真机调试。Provision Profile里集成包含了step 3创建的development cert, step 4创建的device和step 5创建的app ID的信息)

1.  在apple web site "provisioning portal > Provisioning" page, click "new Profile"  button

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")

Step 8: import " ios_development.cer" file created by step 3 and " aps_development.cer" file created by step 6 to “ keychain access"
1. double click " ios_development.cer" file to import it to “ keychain access"
2. double click " aps_development.cer" file to import it to “ keychain access"
3.然后在keychain access里的"Login > My Certificates"里会看到这2个cert:" iPhone Developer: Tomson Xu" cert and " Apple Development IOS Push Services" cert
Step 9: add provisioning profile file download in step 7 to your device
1. 把iphone/ipod连接上电脑
2. drag the provision profile file (extension is " .mobileprovision") to "Xcode" in the desktop dock 
3. 这时会打开xocde里的" organizer" window。如果没有打开,就在select Xcode menu "window > organizer"
4. 在左边的panel里select "Library > Provisioning Profiles",你会看到你step 7创建的provision profile in the list。另外在你的device的"Provision Profiles”里也会看到它。
5. 如果你在apple site更新了你的provisioning profile,在"organizer" window的"Library > Provisioning Profiles"和Device "Provisioning Profiles"删除旧的,然后在"Library > Provisioning Profiles"里click "Refresh" button
这个时候你就可以在真机上调试了,即使是真机上测试push notification也是可以的( 当然,我是说iphone side for push notification is ready)!
下面的步骤是讲解如何在你的app里添加一些代码来实现最简单的push notification功能,以及如何设置server side (即apns provider),用于push message。
Step 10 在你的app里添加一些代码来实现最简单的功能
1. 创建一个"single view application" project,为省事, 你设置的"Company Identifier" + "Production“必须和step 5创建的App ID的"bundle identifier"一致。
2. 在 AppDelegate.m file的" didFinishLaunchingWithOptions" method里,添加下列代码 (用于为app register push notification feature):
    // Let the device know we want to receive push notifications[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

3. 在 AppDelegate.m file里添加下列2个methods ( 用来handle register remote notification with device token和register error的events

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{NSLog(@"My token is: %@", deviceToken);
}- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{NSLog(@"Failed to get token, error: %@", error);
}

4. 运行该app in real device ( simulator doesn't support push notification)。这时你会在device上看到一个popup window (该窗口只会出现一次,重装app不会再出现),提示你该app会send push notification给你,如果同意则click OK,不同意则click " Now allow”。如果选择了OK,那么在" Setting > Notifications“里会有你的app在list里。而且这时你的Xcode output console会显示你的device token。

Step 11:  step 2生成的“MobileCAPKey.p12” file和step 6生成的"aps_development.cer" file是用于APNS provider side的源文件,APNS Provider side进行push message时要用到的"cert + key" file就是通过这2个file来生成。该Step就是用来生成for APNS provider side (php version)要用到这个"cert + key" pem file.
step 11.1 open Terminal, go to Desktop (假设这2个file都在desktop里)
step 11.2 执行下列命令来生成和apns cer file对应的pem file " MobileCAPCert.pem"
openssl x509 -in aps_development.cer -inform der -out MobileCAPCert.pem

step 11.3 执行下列命令来生成和private key .p12 file对应的pem file " MobileCAPKey.pem" ( 注意:执行过程会要求你输入"MobileCAP.p12"创建时设置的密码,以及设置"MobileCAPKey.pem”的密码

openssl pkcs12 -nocerts -out MobileCAPKey.pem -in MobileCAPKey.p12

Step 11.4 执行下列命令把step 11.2生成的cert pem file和step 11.3生成的key pem file合成为一个pem file  " MobileCAPCK.pem"

cat MobileCAPCert.pem MobileCAPKey.pem > MobileCAPCK.pem
Step 12: step 2生成的“MobileCAPKey.p12” file和step 6生成的"aps_development.cer" file是用于APNS provider side的源文件,该step是简单测试这2个file是否有效
step 12.1 open Terminal, go to Desktop (假设这2个file都在desktop里)

Step 12.2 执行下列命令来测试是否能够connect apple提供的不经加密( 即不需使用任何证书!)的APNS server

telnet gateway.sandbox.push.apple.com 2195

如果你看到下列输出,则表示你的电脑可以connect APNS. 如果出现error,那么check你的firewall是否允许 outgoing connections on port 2195。

Trying 17.172.233.65...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.

Press Ctrl+C to close the connection.

Step 12.3  执行下列命令来测试是否能够connect apple提供的经加密( 需使用step 11.2 and 11.3生成的2个pem file!)的APNS "sandbox“ server for development.
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert MobileCAPCert.pem -key MobileCAPKey.pem

执行过程中会要你输入MobileCAPKey.pem生成时设置的密码。如果connect server成功,就会等待你输入字串,你可以输入任意字串,然后回车,就会disconnect server。如果连接不成功,则openssl会显示错误信息。

注意:实际上有2个APNS servers: the “sandbox” server (用于testing) the live server(用于production mode)。我们这里测试的是sandbox server。live apns server的操作类似。

Step 13 创建provider server side (php version)

1. Download SimplePush PHP code to your mac machine and then unzip it.

2. 去掉SimplePush folder里的pk.pem (它没用),把step 11.4生成的"MobileCAPCK.pem" copy toSimplePush folder

3. 修改simplepush.php file下面几行:

// Put your device token here (without spaces):

//device token来自Step 10的第4点,在output console获取,注意:要去掉前后的尖括号,和中间的所有空格
$deviceToken = '43fcc3cff12965bc45bf842bf9166fa60e8240c575d0aeb0bf395fb7ff86b465';
// Put your private key's passphrase here:

//该值是step 11.3生成MobileCAPKey.pem时设置的密码
$passphrase = '123456';
// Put your alert message here:
$message = 'My first push notification!';

//.....
stream_context_set_option($ctx, 'ssl', 'local_cert', 'MobileCAPCK.pem');

4. 在terminal window里,go to the simplepush folder,然后执行下列命令,你的iPhone应该会收到一条push message。

php simplepush.php

注意:如果你的app在iphone里是正在运行,而且app是在front end时,当它收到push message时是不会出现在iPhone顶部的notification area的!

Step 14 创建provider server side (c# version)

step 11生成了用于php的APNS cert (extension is pem),而如果用c#作为apns provider,则要使用.p12 format cert,它的生成方式比step 11简单很多:

step14.1. open "keychain access",然后找到"login > My Certificates > Apple Development IOS Push Services: xxxx" cert (该cert是在step 8导入到keychain access的)

你会看到该cert下包含了Step 1生成的private key 


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 open the project。然后我们只需要"JdSoft.Apple.Apns.Notifications"和"JdSoft.Apple.Apns.Notifications.Test",其他的都可以删掉。Right click "JdSoft.Apple.Apns.Notifications.Test", select "Set as Startup Project"

step14.4 把step14.2生成的MobileCAPCK_For_CSharp.p12 file复制到“JdSoft.Apple.Apns.Notifications.Test\bin\Debug”目录下

step14.5 打开"JdSoft.Apple.Apns.Notifications.Test"下的"Program.cs",修改下面几行

         //Put your device token in herestring testDeviceToken = "fe58fc8f527c363d1b775dca133e04bff24dc5032d08836992395cc56bfa62ef";//Put your PKCS12 .p12 or .pfx filename here.// Assumes it is in the same directory as your appstring 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 stringstring p12FilePassword = "yourpassword";

step 14.6 Rebuild the whole project, and then Run!

Step 14.7 把APNS-SHARP移植到web project里

1. In visual studio, create a new "web site"

2. right click the web site root node, select "Add reference...", select "browse" tab, and then choose "Newtonsoft.Json.Compact.dll" in APNS-SHARP libray "reference" folder

2. right click the web site root node, select "Add ASP.NET Folder > App_Code".

3. right click "App_Code" node, select "new folder", folder name任取。然后把APNS-SHARP libray "JdSoft.Apple.Apns.Notifications"目录里的所有.cs文件copy到该新建目录下。

4. 把step14.2生成的MobileCAPCK_For_CSharp.p12 file复制到web site root node下。

5. 然后把APNS-SHARP libray "JdSoft.Apple.Apns.Notifications.Test"目录里的Program.cs里代码适当改下,然后复制到Default.aspx.cs里(记得要import JdSoft.Apple.Apns.Notifications),就做成一个最简单的asp.net push notification web site.

参考文档:

iphone在真机测试

官方文档 https://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/ios_development_workflow/00-About_the_iOS_Application_Development_Workflow/introduction.html#//apple_ref/doc/uid/TP40007959-CH1-SW1

http://www.cocoachina.com/bbs/read.php?tid=68636

http://blog.csdn.net/dotphoenix/article/details/5271727

http://fstoke.me/blog/?p=1805

http://hi.baidu.com/zhaodingfeng/blog/item/381b7e54025cab42564e00fa.html

在真机测试其实最终是体现在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

aspn provider c# version  https://github.com/Redth/APNS-Sharp

iOS: iphone在真机测试以及apns的设置相关推荐

  1. iOS Developer:真机测试

    转载请注明出处,原文地址http://my.oschina.net/joanfen/blog/167730 如果本文不能解决您的问题请移步:http://my.oschina.net/u/124536 ...

  2. iOS Developer:真机测试证书申请

    关于证书选项呈灰色的情况,因为苹果的开发者中心改版,很多人遇到这个问题,本来放在文中的,现在提到前面来 如果出现ios development一项为灰色不可点击状态,苹果的说法是 如果您要为此电脑添加 ...

  3. iOS:Xcode8以下真机测试iOS10.0和iOS10.1配置包

    一.介绍 xcode的升级都已经到8系列了,可是还是有很多开发者使用的xcode还是7系列,然而xcode7...最多支持9.3,无法给升级到10.0和10.1的iPhone手机用户进行真机测试.此时 ...

  4. hbuilderx ios自定义基座真机测试

    任务描述: 用uniapp框架写了一个app应用,需要在ios苹果手机上真机运行测试. hbuilderx不再支持标准基座真机运行了,需要自定义基座运行 制定自定义基座需要准备的材料: ios的app ...

  5. iOS 开发:真机测试

    真机测试 在成功加入iOS Developer Program之后,对于开发者来说,首先要实现的就是真机测试.下面详细介绍实现真机测试的过程. 先总体介绍一下实现真机测试的步骤,如下图所示: 总的来说 ...

  6. iOS开发关于真机测试_skybeauty_新浪博客

    1.  iOS 开发证书: 开发证书 (Development Certificate) 是一个后缀为 .p12 的文件(Certificates.p12): 在Mac 系统下, 双击这个文件,这个证 ...

  7. uni-app开发ios,免费真机测试,发布全流程

    uni-app开发IOS应用 一.下载安装hbuilder.xcode. uni-app官网:uni-app官网 hbuilder下载地址:HBuilderX 文档 说明:hbuilder主要用来生成 ...

  8. ios添加设备真机测试,以及Undefined symbols for architecture x86_64:''错误

    问题今天坑了好久,然后找了各种资料 添加设备这个直接去开发者中心添加一个设备进去就好,具体流程百度,第二个问题是属于路径不对或者是静态库没有添加成功,项目可以看到,到时路径找不到,你把静态库拖到桌面之 ...

  9. iphone 4 程序开发:真机测试 (免费无99刀)

    要给iphone开发程序,我们需要一个mac系统(我是用pc机装的lion10.7),以及xcode(我用的是xcode4.1和ios4.3sdk),当然,你还需要一台iphone来进行真机测试. 当 ...

最新文章

  1. 网络设置巨形帧_Trunk的概念与设置
  2. C ++ 11引入了标准化的内存模型。这是什么意思?它将如何影响C ++编程?
  3. Android学习视频
  4. 计算机组成原理精品课程申报书,【计算机科学与技术专业】【毕业设计】计算机组成原理精品课程平台的设计与实现...
  5. CVer入门必备:计算机视觉的深度学习实践
  6. elasticsearch——海量文档高性能索引系统
  7. 复旦大学计算机学院博士生王斌,复旦大学计算机科学技术学院博士生刘鹏飞荣获...
  8. pyqt按钮关闭窗口_PyQt5按钮单击事件,退出程序
  9. java多线程队列_java多线程消费者生产者模式(BlockingQueue 通过阻塞队列实现)
  10. 【Python爬虫】入门知识
  11. breakall lisp文件_breakall.lsp下载
  12. 【Pix4d精品教程】打开Pix4DMapper时提示Pix4DMapper.exe已停止工作的完全解决办法
  13. html表单代码有哪些,HTML常用代码有哪些
  14. php生成手机桌面快捷方式,php三种创建桌面快捷方式
  15. vb局域网连接mysql_VB 用代码进行局域网内数据库的连接
  16. Day2--安装MediaWiki搭建自己的个人百科
  17. XXE漏洞(XML外部实体注入)
  18. 小提琴统计图_小提琴图解读 统计学
  19. yapi文档转换jmx脚本
  20. 别让那些贩卖焦虑的人,打扰到你的人生

热门文章

  1. sketch(三)--插件
  2. 用keil4打开keil5的工程文件导致卡死解决办法
  3. [CS-161]网络钓鱼(phishing)
  4. 另类弹窗十倍放大流量
  5. dux修改index.php,[mcj]Dux大前端主题增加网站顶端公告模块
  6. 谷歌大脑深度学习炼丹指南出炉,Hinton点赞!
  7. html网页盒子整体放大,网页前端开发制作盒子拖拽、缩放
  8. 跟杨春娟学Spring笔记:AOP之SpringAOP引介通知
  9. 施耐德PLC TM218如何实现远程上传下载程序?
  10. linux 保存文件名乱码怎么办,Linux下文件名乱码的解决方法