Apple Push Notification サービス(APNs) の実装方法




Local NotificationPush Notification


ApnsPHP: Apple Push Notification & Feedback Provider
http://code.google.com/p/apns-php/

EASY APNS
APPLE PUSH NOTIFICATION SERVICE USING PHP & MYSQL
http://www.easyapns.com/
(PHP)(Objective-C) 
HP(10)

 ApnsPHP 使
EASY APNS  mysqli 使(T_T))


1. 


 iOS Provisioning Portal  Push NotificationsApp IDs
 App IDs  
 

 使
  
 App IDs ID 

2. 


iOS  Remote Notification APNS ID
( iOS  APNS )


iOS  Remote Notification APNS  
( PHP)

 APNS 
1
2
3
4
5
6
7
// アプリケーションが起動した際の処理
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Remote Notification を受信するためにデバイスを登録する
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge
                                                                           | UIRemoteNotificationTypeSound
                                                                           | UIRemoteNotificationTypeAlert)];

APNS から返されるデバイストークンに付加されている文字をカットする

1
2
3
4
5
6
7
// デバイストークンを受信した際の処理
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
 
    NSString *deviceToken = [[[[devToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""] 
                                                      stringByReplacingOccurrencesOfString:@">" withString:@""] 
                                                      stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSLog(@"deviceToken: %@", deviceToken);

プッシュ通知は、NSDictionary で渡される

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// プッシュ通知を受信した際の処理
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
#if !TARGET_IPHONE_SIMULATOR
    NSLog(@"remote notification: %@",[userInfo description]);
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
 
    NSString *alert = [apsInfo objectForKey:@"alert"];
    NSLog(@"Received Push Alert: %@", alert);
 
    NSString *sound = [apsInfo objectForKey:@"sound"];
    NSLog(@"Received Push Sound: %@", sound);
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
 
    NSString *badge = [apsInfo objectForKey:@"badge"];
    NSLog(@"Received Push Badge: %@", badge);
    application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
#endif
}

3. SSL Distribution証明書、秘密暗号鍵の取得とサーバへの配置


SSL DistributionAPNs



OK

server_certificates_bundle_sandbox.pem
entrust_root_certification_authority.pem

How to generate a Push Notification certificate and download the Entrust Root Authority certificate 

http://code.google.com/p/apns-php/wiki/CertificateCreation

CertificateCreation
How to create a Push Notification certificate in iPhone Developer Program Portal 

Generate a Push Certificate
Push Notification 

Verify peer using Entrust Root Certification Authority
Download the Entrust Root Authority certificate directly from Entrust Inc. website:

4. PHP 


iPhone 
ApnsPHP  sample_push.php  OK
APNS 

 server_certificates_bundle_sandbox.pem
 entrust_root_certification_authority.pem


^_^

PHP 



ApnsPHP (at revision 100)  ApnsPHP-r100.zip  sample_push.php 

2(T_T)
2

1
2
3
4
5
6
// Instanciate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
	ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
//	'server_cerificates_bundle_sandbox.pem'		// 綴りが間違ってる
  'server_certificates_bundle_sandbox.pem'
);

Apple Push Notification サービス(APNs) の実装方法」への12件のフィードバック




  1. TARGETSCodeSign
    iOS Team Provisioning Profile
    Appaps-environment


    PROJECTCodeSign







    • ^_^
        

      Appaps-environment


      App IDs  xcode  Bundle Identifier xcode TARGETS  Build Settings  Code Signing Identity  APN  

      TARGETS  Info  Bundle identifier APN  
       App ID OK

  2. redwing1300







  3. (^^)



  4. Windows


    PHPAPNs




    Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in C:\xampp\htdocs\web\MessagePush\push.php on line 64

    Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in C:\xampp\htdocs\web\MessagePush\push.php on line 64

    Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in C:\xampp\htdocs\web\MessagePush\push.php on line 64

    MacPEM)




    (^_^)v



  5. PUSHPHP
    APNS



  6. (^^)
    Local NotificationPush Notification

    APNs  ApnsPHP (Д`)
    ApnsPHP 
     Push.php / Server.php 




  7. $sRet = pack(CNNnH*, self::COMMAND_PUSH, $nMessageID, $nExpire > 0 ? time() +              $nExpire : 0, self::DEVICE_BINARY_SIZE, $sDeviceToken);
    $sRet .= pack(n, $nPayloadLength);
    $sRet .= $sPayload;

    Command1identifier(APNs)7

    pack調!!



    $sErrorMessage = fread(fp,6);

    unpack(Ccommand/CstatusCode/Nidentifier, $sErrorMessage);
    caseNO沿Exception
    ??!!






  8.  pack() 調
    http://php.net/manual/ja/function.pack.php

    (^^)
  9. ピンバック: APNsのProvisioning Profileが有効にならないときは、ここを疑おう « 大阪のアンドロイド開発会社 ノーティス

  10. ピンバック: Easy APNSとEasyAPNSPanel

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です