升级到XCode 8后,带IOS 10的iphone无法再接收推送通知。
我可以使用代码正确获取设备令牌(swift 3): func application(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?) - >布尔{
print("start didFinishLaunchingWithOptions")
// Register the supported interaction types.
let types = UIUserNotificationType([.alert, .badge, .sound])
let mySettings = UIUserNotificationSettings(types: types, categories: nil)
UIApplication.shared.registerUserNotificationSettings(mySettings)
// Register for remote notifications.
UIApplication.shared.registerForRemoteNotifications()
return true
}
func application(_ application:UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken:Data){
print("start didRegisterForRemoteNotificationsWithDeviceToken")
let deviceTokenString = ((deviceToken as NSData).description.trimmingCharacters(in: CharacterSet(charactersIn: "<>")) as NSString).replacingOccurrences(of: " ", with: "")
....
}
我在服务器端的PHP总是返回200,这是成功的。 $ ch = curl_init(); if(!defined('CURL_HTTP_VERSION_2_0')){ define('CURL_HTTP_VERSION_2_0',3); } curl_setopt($ ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0); $ pem_file ='/ var / my.pem'; $ pem_secret ='xxxxxx'; $ apns_topic ='xxxxxx'; $ apns_expiration = 2;
$change_alert = "{
\"aps\": {
\"alert\": \"$alert_message\",
\"badge\": $badge,
\"sound\": \"default\"
},
\"xxxxxxxx\": \"$xxxxxx\"
}";
$url = "https://api.development.push.apple.com/3/device/$device_token";
//$url = "https://api.push.apple.com/3/device/$device_token";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $change_alert);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: $apns_topic", "apns-expiration: $apns_expiration"));
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
//curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
对这个问题有任何想法吗?
BTW,XCode 8不像以前的版本那么稳定。
=============== CURL日志:
* Trying 17.188.135.156...
* Connected to api.push.apple.com (17.188.135.156) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLSv1.2 / ECxxxxxxxxxxxxxxxxxx
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=api.push.apple.com; OU=management:idms.group.533599; O=Apple Inc.; ST=California; C=US
* start date: Aug 28 19:03:46 2015 GMT
* expire date: Sep 26 19:03:46 2017 GMT
* subjectAltName: host "api.push.apple.com" matched cert's "api.push.apple.com"
* issuer: CN=Apple IST CA 2 - G1; OU=Certification Authority; O=Apple Inc.; C=US
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* TCP_NODELAY set
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7f2d6eda3970)
> POST /3/device/3xxxxxxxxxxxxxxxxxx HTTP/1.1
Host: api.push.apple.com
Accept: */*
apns-topic: xxxxxxxxxx
apns-expiration: 0
Content-Length: 316
Content-Type: application/x-www-form-urlencoded
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
* We are completely uploaded and fine
< HTTP/2.0 200
< apns-id:AF034xxxxxxxxxxxx0F9F27
<
* Connection #0 to host api.push.apple.com left intact