`
sillycat
  • 浏览: 2551302 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

APNS(2)Try to Finish the first Example

 
阅读更多
APNS(2)Try to Finish the first Example



Brief Overview


1. An app enables push notifications.

2. The app receives a "device token".

3. The app sends the device token to your server

4. The server sends a push notification to the Apple Push Notification Service

5. APNS sends the push notification to the user's device.



After the user's device receives the push notification, it shows an alert, plays a sound and/or updates the app's icon.



Need for Push Notifications
An iPhone or iPad

An iOS Developer Program membership

A VPS(Virtual Private Server)



Anatomy of a Push Notification
{

     "aps":

     {

          "alert": "Hello, world!",

          "sound": "default"

     }

}



{

     "aps":

     {

          "alert":

          {

               "action-loc-key": "Open",

               "body": "Hello, world!"

          },

          "badge": 2

     }

}



Push Notification Gotchas
They are not reliable. There is no guarantee. Push notifications are fire-and-forget, there is no way to find out what the status of a notification is. APNS will try to deliver the last notification after the device is back online, but once it times out, the push notification will be lost forever.



Provisioning Profile and Certificates
We need an SSL certificate.



Generating the Certificate Signing Request(CSR)
Use 'Command' + 'Blank' to find the Keychain Access application on my MAC book.

'Certificate Assistant' and choose 'Request a Certificate from a Certificate Authority…'



Enter my email which I register on the iOS developer. And give a 'Easy iOS sample' for common name and select the 'Save to disk'.



Save the file on the desktop as easyiossample.certSigningRequest.



Select 'login' on the top and 'Keys' at the left bottom, we will see the private and public key we just created. Select the private key and export to desktop with name EasyiOSSampleKey.p12 and use a password to protect it.



Making the App ID and SSL certificate
Go to this URL

https://developer.apple.com/ios/manage/overview/index.action



'App IDs' ---> 'New App ID'

Description: EasyiOSExample

Bundle Seed ID:

Bundle Identifier:



click on "Configure"



check the Enable for Apple Push Notification service box and click on the 'Configure' button for the Development Push SSL Certificate.



continue to find the Certificate Signing Request(CSR).  ----> Generate -----> Done



click Download to get the certificate. It is named aps_development.cer.



Making a PEM file
Till now, I have 3 files:

The CSR

The private key as a p12 file

The SSL certificate, pas_developer.cer



I will combine the certificate and the private key into a single file that uses the PEM format.



>openssl x509 -in aps_development.cer -inform der -out easyiossample_cert.pem

>openssl pkcs12 -nocerts -out easyiossample_key.pem -in EasyiOSSampleKey.p12

Enter Import Password:

MAC verified OK

Enter PEM pass phrase:

Verifying - Enter PEM pass phrase:



First password is for open the private key. Other 2 passwords are creating the protection for PEM file.



Put the 2 PEM files together

>cat easyiossample_cert.pem easyiossample_key.pem > ck.pem



I verify the certificate and key like this>

>telnet gateway.sandbox.push.apple.com 2195



>openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert easyiossample_cert.pem -key easyiossample_key.pem



But I got this error, Error Message:

Verify return code: 20 (unable to get local issuer certificate)



I will find out if this is a problem and solve it later.



Making the Provisioning Profile
Select the 'Provisioning' Menu. -----> New Profile

Profile Name: EasyiOSSample Development

certificates:

App ID:

Devices:



Before do that, I need to 'Certificates' --- Upload my CSR.



Go to the 'Devices' and active my devices.



We are creating provisioning profile, because each push app needs to have its own profile that is connected to the proper App ID.



After finish that, we can download and get a file named Easy iOS Sample.mobileprovision.



All these accounts things are done, I will go on to write the sample client.



References:
http://w54653520.iteye.com/blog/1319595



http://code.google.com/p/javapns/

http://www.ibm.com/developerworks/cn/mobile/mo-ios-push/

http://hz-chenwenbiao-rr.iteye.com/blog/1604589



http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2

http://www.raywenderlich.com/tutorials
分享到:
评论

相关推荐

    开源项目-sger-go-apns2.zip

    而Go-apns2项目就是针对这一服务的客户端库,它简化了与APNs服务器通信的过程。 首先,让我们了解一下Go语言。Go,也被称为Golang,是由Google开发的一种静态类型的、编译式的、并发的、垃圾回收的、面向对象的编程...

    Java向苹果服务器推送消息(Java实现HTTP/2协议发送APNS)

    APNs(Apple Push Notification service)是苹果公司提供的推送服务,允许开发者将消息推送到用户的iOS设备上。本教程将重点讲解如何使用Java实现基于HTTP/2协议的APNS推送,并假设你已经对JDK 11及以上版本有一定的...

    notnoop-java-apns.zip_com.notnoop.apns_java apns_notnoop apns_no

    2. 创建`ApnsService`实例:通过`ApnsServiceBuilder`指定服务器地址和证书。 3. 构建`ApnsNotification`:设置通知的各种属性,如设备令牌、标题、正文等。 4. 发送通知:调用`ApnsService`的`push()`方法,传入...

    开源项目-sideshow-apns2.zip

    开源项目“sideshow-apns2”是一个用Go语言编写的工具,用于实现Apple的新型HTTP/2推送通知服务(APNs)协议。这个项目旨在帮助开发者更高效、更可靠地向iOS、iPadOS以及macOS设备发送推送通知。在本文中,我们将...

    苹果 APNS2 推送DEMO

    【苹果APNS2推送DEMO】是针对Apple Push Notification service(APNs)第二版的一个示例项目,旨在帮助开发者理解和实现iOS与macOS应用的远程通知功能。APNs是苹果公司提供的服务,允许应用程序在后台接收来自服务器...

    ios 开发制作push证书(apns)

    2. 私钥文件(通常以.p12为扩展名):用于在客户端与服务器之间建立加密通信。 3. SSL证书文件(.cer):用于标识服务端。 在创建证书之前,开发者需要登录到iPhone Developer Connection Portal(***),点击“App...

    .net APNS推送

    .NET APNS推送是一个基于.NET框架实现的用于向Apple Push Notification Service (APNS)发送推送通知的项目。APNS是苹果公司提供的服务,允许开发者通过云端将实时消息推送到iOS、iPadOS、watchOS以及macOS设备上的...

    C# apns 推送

    【C# APNS推送】 APNS(Apple Push Notification Service)是苹果公司提供的一个服务,用于向iOS、iPadOS、watchOS、tvOS等设备发送实时通知。开发者可以通过使用APNS来实现在应用未运行时向用户发送消息的功能,...

    ApnsPHP_apnsphp_php_

    APNSPHP是一个专门为苹果推送通知服务(Apple Push Notification service,简称APNs)设计的PHP库。这个库的主要目的是帮助PHP开发者方便地与苹果服务器进行通信,以便向iOS、macOS和watchOS设备发送推送通知。从...

    最新java整合APNS推送服务

    Java整合APNS推送服务是将Java应用程序与Apple Push Notification Service(APNS)相结合,以便能够向iOS和tvOS设备发送即时消息。APNS是苹果公司提供的一个服务,它允许开发者在用户不打开应用的情况下,向他们的...

    php实现的APNs服务端

    需要注意的是,APNs对推送消息的大小有限制,一般不超过2KB。 6. **错误处理**: APNs会在接收推送消息时返回一个反馈,如果设备Token无效或者推送失败,会返回相应的错误代码。服务端需要正确处理这些反馈,以便...

    JavaAPNS开源库apns4j.zip

    apns4j 是 Apple Push Notification Service 的 Java 实现!Maven:   <groupId>com.github.teaey</groupId>   <artifactId>apns4j   <version>1.0.1  示例代码:KeyStoreWraper keyStore = ...

    java调用apns推送的实现

    2. **构建连接**:使用Java的SSL套接字库建立与APNs服务器的SSL/TLS连接。你需要导入之前下载的.pem文件,将其转换为KeyStore,然后设置KeyManagerFactory和SSLContext来建立安全连接。 3. **构建推送消息**:APNs推...

    C# .net 实现APNS

    2. **创建连接**:使用`System.Net.Security.SslStream`类,你可以建立一个安全的SSL/TLS连接到APNS服务器。有两个不同的环境:生产环境和沙盒环境,对应不同的服务器地址。确保根据应用的状态(发布或测试)选择...

    apns.jar包用于apns推送

    apns.jar包,用于apns推送,直接导入就可以使用了

    apns iphone源码下载

    2. **APNs的认证过程** 在使用APNs时,开发者需要获取两个密钥:一个用于生产环境,另一个用于开发环境。这些密钥存储在.p8格式的文件中,并通过苹果的证书管理工具生成。这些密钥与Apple Developer Account关联,...

    iOS苹果推送apns测试工具.zip

    2. **推送类型**:APNs支持两种推送类型,即“显示”(显示在通知中心)和“声音”(伴随声音)。显示通知通常包含标题、正文和可能的附加信息,而声音通知则可以与特定的声音文件关联,以提醒用户。 3. **推送认证...

    iphone消息推送APNS

    **苹果推送通知服务(Apple Push Notification service,简称APNS)** APNS是苹果公司提供的一项服务,用于向iOS、iPadOS、watchOS、tvOS以及macOS设备推送通知。通过APNS,应用开发者可以在他们的应用不在前台运行...

Global site tag (gtag.js) - Google Analytics