基本上,我已经按照apns-php的证书创建,一些教程如mobiforge上的教程,还有Matthijs Hollemans的教程去操作了。但是,我无法将任何通知发布到我的iPad 2上。
基本上,这些是我所做的步骤:
- I followed the CertificateCreation tutorial, I came out with
server_certificates_bundle_sandbox.pem
,entrust_root_certification_authority.pem
. Followed the tutorial specified in mobiforge blog, I successfully created the App ID, provisioning profile and linked them together nicely.
- Description: APNTest
- Bundle Seed ID: Use Team ID
- Bundle Identifier: com.learn.APN
Then I enable the Development Push SSL Certificate (only for now) using the same certificate request I have used just now to get the certs, and I download it and install it into my keychain.
I downloaded my provisioning profile in
.mobileprovision
file and loaded it into Xcode's Organizer under my iPad 2 device.Next I create a simple application with only these codes:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; // Override point for customization after application launch. return YES; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"%@", deviceToken); } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Error: %@", error); }
Then I configure the build parameters:
- Targets > Info > Build Identifier: net.learn.APN
- Targets > Build Settings > Code Signing Identity > (I chose the provisioning profile I have installed just now, and it automatically selects the identical profiles for my Debug and Release)
I build and run the application on my iPad 2. My application requesting for Push Notification and after I approved it, the Token ID appeared in my console:
2012-01-19 12:43:26.345 TestAPN[578:707] <3cb08612 9392996b 5332d2fc 5adce03d 994f8959 d7a2ac38 de7bed52 c8e0778e>
I used apns-php, changed the device ID (raw 64 hexa-values), then run the
sample_push.php
. Script ran successfully, but my device is not receiving any notificationThen I try to use the SimplePush.php. A "Message successfully delivered" appeared, but my iPad still doesn't receive any notification from APN
我还发现了“APN反馈服务”,我根据SimplePush写了这个(但不幸的是它是空的)。现在我该怎么办?
<?php
// Put your private key's passphrase here:
$passphrase = '';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'server_certificates_bundle_sandbox.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://feedback.sandbox.push.apple.com:2196', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
while (!feof($fp)) {
$data = fgets($fp, 1024);
var_dump(unpack("N1timestamp/n1length/H*devtoken", $data));
}
// Close the connection to the server
fclose($fp);
注意:
1.我知道开发/生产证书之间的差异。 2.iPad没有越狱,运行iOS 5.0.1 3.其他App Store应用程序可以正常接收通知。 4.XCode 4.2.1,Lion 10.7.2
我希望我没有重复这里的任何问题.. ;)
编辑:
当我运行php simplepush.php然后php feedback.php时,我收到了一个带有我的设备ID的反馈。我的应用程序仍然在iPad上,这是否意味着我的设备ID是错误的?
[root@ip-xx-xx-xx-xx SimplePush]# php feedback.php
Connected to APNS
array(3) {
["timestamp"]=>
int(1326962028)
["length"]=>
int(32)
["devtoken"]=>
string(64) "3cb086129392996b5332d2fc5adce03d994f8959d7a2ac38de7bed52c8e0778e"
}
感谢。 编辑: 在经过Matthijs Hollemans所写的所有步骤的反复努力和重做后,我终于让它工作了。因此问题在于生成的PEM文件不正确...嗯。