Notifications IOS 8中的远程推送通知
我对IOS 8.1中的远程推送通知有问题。我使用以下代码将消息推送到带有IOS 8的iPhone6,但它没有工作,设备没有收到任何消息。sameone能帮我解决这个问题吗?非常感谢 php代码:Notifications IOS 8中的远程推送通知,notifications,ios8,push,Notifications,Ios8,Push,我对IOS 8.1中的远程推送通知有问题。我使用以下代码将消息推送到带有IOS 8的iPhone6,但它没有工作,设备没有收到任何消息。sameone能帮我解决这个问题吗?非常感谢 php代码: <?php $passphrase = 'masterkey'; $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'cer/pushcert.pem'); stream_con
<?php
$passphrase = 'masterkey';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'cer/pushcert.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 1, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
$deviceToken=$deviceToken_in_database; //read device token from database
$message = "here is test";
$body['aps'] =array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
$msg= chr(0) . chr(0) . chr(32) . pack('H*', $deviceToken) . chr(0) . chr(mb_strlen($payload)) . $payload;
$result_tmp = fwrite($fp, $msg);
if (!$result_tmp){
echo "failed";
}else{
echo "successful";
}
fclose($fp);
?>
目标c代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// register remote Notification in ios 8
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
return YES;
}
……
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// get push device token
NSString * token = [NSString stringWithFormat:@"%@", deviceToken];
//Format token as you need:
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
token = [token stringByReplacingOccurrencesOfString:@">" withString:@""];
token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""];
//NSLog(@"deviceToken: %@", token);
device_token=token;
}
可能重复检查此链接,已解决。参考: