开发者

How to receive Push notification message in iphone app?

开发者 https://www.devze.com 2023-03-19 14:43 出处:网络
I created .pem file following steps Log-in to the iPhone Developer Program Portal. Choose App IDs from the menu on the right.

I created .pem file following steps

  1. Log-in to the iPhone Developer Program Portal.
  2. Choose App IDs from the menu on the right.
  3. Create an App ID without a wildcard.
  4. Click the Configure link next to this App ID and then click on the button to start the wizard to generate a new Development Push SSL Certificate.
  5. Download this certificate and double click on aps_developer_identity.cer to import it into your Keychain
  6. Launch Keychain Assistant and click on My Certificates on the left
  7. Expand Apple IOS Development Push Services and select Apple IOS Development Push Services AND my private key
  8. Right-click and choose "Export 2 elements..." and save as cert.p12.
  9. Open Terminal and change directory to location used to save cert.p12 and convert the PKCS12 certificate bundle into PEM format using this command openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts 10.Now i use this PEM file as my certificate in ApnsPHP!

while i use the url in the browser it display; {"aps":{"alert":"hi","badge":1,"sound":"beep.wav"}}

I am using this code to receive notification in iphone app

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];


    NSLog(@"\n\n\n\nRegistering for push notifications...\n\n\n\n");    
    [[UIApplication sharedApplication] 
     registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeAlert | 
      UIRemoteNotificationTypeBadge | 
      UIRemoteNotificationTypeSound)];

}


- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];

    NSLog(@"\n\n\n\n\n device token===%@\n\n\n\n",token);
    //DeviceRegisterer *registrar = [[DeviceRegisterer alloc] init];
    //[registrar registerDeviceWithToken:token];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    NSLog(@"failed to regiser %@", err);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSLog(@"notification options %@", userInfo);

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Super" message:@"welcome" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    for (id key in userInfo) {


        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
        UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your tit开发者_如何学Gole here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
        [myTextField setBackgroundColor:[UIColor whiteColor]];
        myTextField.text = [userInfo objectForKey:key];
        [myAlertView addSubview:myTextField];
        [myAlertView show];
        [myAlertView release];

    }    

}

But am not able to receive the notification message. Please help to resolve this problem.

Thanks in advance, Senthilkumar


You are not using a server to send the message. The pem key is meant to be used by a server to send the message. I think that you cannot use your iphone app to send directly a push message. If your server is using php try to find in this site the code to delivery the notifications. Note: On my server the ApnsPHP code do not work at all, I used a simple php script found in stackOverflow (sorry do not remember the link) to manage it and works.


I solved this problem. Problem in the php .pem file attactment . thanks for gave idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消