Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 推送通知不存在';行不通_Php_Iphone_Apple Push Notifications - Fatal编程技术网

Php 推送通知不存在';行不通

Php 推送通知不存在';行不通,php,iphone,apple-push-notifications,Php,Iphone,Apple Push Notifications,我正在开发一个需要推送通知的应用程序。 下面我将用php实现推送通知。 所以我用的是生产证书。 这是ApplicationLegate中的代码: - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { const unsigned* tokenBytes = [deviceToken bytes]; NSStr

我正在开发一个需要推送通知的应用程序。 下面我将用php实现推送通知。 所以我用的是生产证书。 这是ApplicationLegate中的代码:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    const unsigned* tokenBytes = [deviceToken bytes];
    NSString* tok = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                               ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                               ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                               ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
    NSLog([NSString stringWithFormat:@"token 1 = %@",tok]);
   [[NSUserDefaults standardUserDefaults] setObject:tok forKey:@"token"];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
   NSLog(@"Received notification: %@", userInfo);
}
这是服务器端php页面:

<?php
    //$token = $_GET['t'];
    $token = "xxxxxxxxxxx....xxxxxx";
    $who =$_GET['c'];
    $notification = $_GET['n'];
    $message = 'Hello';
    $badge = 3;
    $sound = 'default';
    $payload = array();
    $payload['aps'] = array('alert' => $message, 'badge' => intval($badge), 'sound' => $sound);
    $payload = json_encode($payload);
    $apns_url = NULL;    
    $apns_cert = NULL; 
    $apns_port = 2195;
$apns_url = 'gateway.push.apple.com';
$apns_cert = 'cert-prod.pem';

    $stream_context = stream_context_create();
    stream_context_set_option($stream_context, 'ssl', 'local_cert', $apns_cert);
    $apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $error,    $error_string, 2, STREAM_CLIENT_CONNECT, $stream_context);
    $device_tokens = array();
    $device_tokens[0] = $token;
    foreach($device_tokens as $key=>$device_token)
    {
        $apns_message = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device_token)) . chr(0) . chr(strlen($payload)) . $payload;
        fwrite($apns, $apns_message);
    }
    @socket_close($apns);
    @fclose($apns);
?>


当我启动php页面时,什么也没有发生。。为什么?谁能帮我

我认为你的代币不正确。尝试:

NSString *token = [NSString stringWithCString:[deviceToken bytes]];
这将有助于:

  NSString *deviceTokenStr = [[[[deviceToken description]
                                stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                               stringByReplacingOccurrencesOfString: @">" withString: @""] 
                              stringByReplacingOccurrencesOfString: @" " withString: @""];

  NSLog(@"Device Token: %@", deviceTokenStr);
NSString*DeviceTokenst=[[[deviceToken描述]
StringByReplacingOfString:@“with String:@”]
StringByReplacingOfString:@“和字符串:@]”发生;
NSLog(@“设备令牌:%@”,DeviceTokenst);

以这种方式,nslog打印类似于Àaè5的内容∆C≤¸u表示代币..正确吗?添加UbQN–xxxxx añ5∆C≤¸u到php代码什么都没有发生:(看起来不太好)尝试:NSString*token=[[NSString alloc]initWithBytes:[deviceToken bytes]长度:deviceToken.length编码:NSASCIIStringEncoding];NSString*tok=[[NSString alloc]initWithBytes:[deviceToken bytes]长度:deviceToken.length编码:NSASCIIStringEncoding];NSLog(@“token=%@),tok);令牌仍然是:(所以令牌必须有空格或<>true?我尝试了,但当我启动php代码时,它没有出现:(没有通知1。是的,没有<>。所以现在我退出了。你是APN的php代码证书吗?