Push notification configuration on Mac

Source: Internet
Author: User
Tags openssl x509

In the egater of the Code, write:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge                                                                           | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];    return YES;}

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{    NSLog(@"my device token=%@",deviceToken);}- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err{    NSString *str = [NSString stringWithFormat: @"Error: %@", err];    NSLog(@"%@",str);}

Then run on the real machine to obtain the devicetoken of the machine.


Double-click certificates. p12 on the generated certificate, click Add, and enter the password.



Configure in xcode:



Then, on the Mac, use the terminal to the folder where the certificate is located. First, check whether the Mac can be connected to the Apple Server:

$ telnet gateway.sandbox.push.apple.com 2195Trying 17.172.232.226...Connected to gateway.sandbox.push-apple.com.akadns.net.Escape character is '^]'.

If the above content appears, it indicates no problem. If not, check if it is a firewall or something, and then convert the p12 and aps_development.cer files into PEM files, merge the converted two PEM files into ck. PEM

$ openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem
$ openssl pkcs12 -nocerts -out PushChatKey.pem -in PushChatKey.p12Enter Import Password: MAC verified OKEnter PEM pass phrase: Verifying - Enter PEM pass phrase: 
$ cat PushChatCert.pem PushChatKey.pem > ck.pem

Check whether success is returned. If a large number of strings are returned, the result is successful. 


Last to http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

Download the simplepush. php file. Note that

<?php// Put your device token here (without spaces):$deviceToken ='d4bb74c6f54d5ff6a2fbb45ea9b083738bdba936a690138f58b4a8b5dc4c65e84';// Put your private key's passphrase here:$passphrase = '111111';// Put your alert message here:$message = 'My first push notification!';
The $ passphrace Mac will be automatically converted into Chinese quotation marks, resulting in connection failure, and the following error is reported,
Kouyuukenmatomacbook-Pro: archive2 kouyuuken $ PHP simpush ush. PHP warning: stream_socket_client (): unable to set Private Key File '/users/kouyuuken/desktop/IOS Project/archive2/ck. PEM 'in/users/kouyuuken/desktop/IOS Project/archive2/simplepush. PHP on line 21 warning: stream_socket_client (): failed to create an SSL handle in/users/kouyuuken/desktop/IOS Project/archive2/simplepush. PHP on line 21 warning: stream_socket_client (): failed to enable crypto in/users/kouyuuken/desktop/IOS Project/archive2/simplepush. PHP on line 21 warning: stream_socket_client (): Unable to connect to SSL: // gateway.sandbox.push.apple.com: 2195 (unknown error) in/users/kouyuuken/desktop/IOS Project/archive2/simplepush. PHP on line 21 failed to connect: 0

Therefore, you must change the quotation marks to English.

If the message is successful, the following message is displayed, and the device receives the notification

kouyuukenmatoMacBook-Pro:Archive2 kouyuuken$ php simplepush.php Connected to APNSMessage successfully delivered




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.