tags:

views:

49

answers:

1

Hi,

I have created one iPhone application. I am getting Device Token. But I am not able to receive notification from APNS. Here I have given the sample code for server in PHP.

I got the code (PHP) from below url:

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

APNS.php

date_default_timezone_set('Asia/Calcutta'); require_once 'ApnsPHP/Autoload.php'; $push = new ApnsPHP_Push( ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 'ApnsPHP/apple_push_notification_production.pem' );

$push->setRootCertificationAuthority('ApnsPHP/entrust_root_certification_authority.pem'); $push->connect(); $message = new ApnsPHP_Message('**'); $message->setCustomIdentifier("Message-Badge-5"); $message->setText('Hello APNs-enabled device!'); $message->setBadge(5); $message->setSound('default'); $message->setCustomProperty('acme2', array('bang', 'whiz')); $message->setExpiry(30); $push->add($message); $push->send(); $push->disconnect(); $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { var_dump($aErrorQueue); }

Objective C:

-(void) applicationDidFinishLaunching:(UIApplication *)application{ NSLog(@"Initiating push notification."); [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; }

-(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ NSLog(@"Device Token : %@", deviceToken); self.currentDeviceToken = [[[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];; NSLog(@"Device Token : %@", self.currentDeviceToken); NSLog(@"Remote type : %d", [[UIApplication sharedApplication] enabledRemoteNotificationTypes]); }

-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{ NSLog(@"Error in registration : %@", error); self.currentDeviceToken = @"no device token"; }

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ NSLog(@"Received Notification"); 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);

NSString *badge = [apsInfo objectForKey:@"badge"];
NSLog(@"Received Push Badge: %@", badge);
application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];

}

Please help me resolve this issues.

Thanks.

A: 

I resolved this issue.

I have created entitlements.plist for my application. Now it is working fine.

jfalexvijay