我创建了一个iPhone应用程序。我正在获取设备令牌。但我无法收到APNS的通知。这里我给出了PHP中服务器的示例代码。
我从以下网址获得了代码(PHP):
http://code.google.com/p/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);
}
-(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];
}
请帮我解决这个问题。
感谢。
答案 0 :(得分:0)
我解决了这个问题。
我为我的应用程序创建了entitlements.plist。现在工作正常。