views:

178

answers:

2

Hi All.

I need to implement push notification in my application. Actually i have to receive messages from the server. Kindly guide me how i can implement push notifications in my iphone application.

A: 

you need to implement these 2 delegate method in your application

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    //NSLog(@"Entered into Method");
    NSString *myDevTokenString = [devToken description];
    NSLog(myDevTokenString);
    self.tokenAsString = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    NSLog(@"token As String:%@", tokenAsString);
    //const void *devTokenBytes = [devToken bytes];
    //NSLog(@"My Token is : %@",devToken);
    //self.registered = YES;
//  UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient-GotToken" message:myDevTokenString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
//  [myAlert show];
//  [myAlert release];
    //[self sendProviderDeviceToken:devTokenBytes]; // custom method

}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

    //UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient" message:@"called -Error- Method" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
//  [myAlert show];
//  [myAlert release];
    NSString *errText = [[NSString alloc] initWithFormat:@"APN Error:%@",err];
    NSLog(@"Error in registration. Error: %@", errText);

}
mihirpmehta
is there any thing else i wanna do.just asking because i have no detailed idea abt posh notifications in iphone application
Abdul Samad
Not anything at client side...
mihirpmehta
+1  A: 

The client side stuff is easy, but if you want a good example we provide one that you can download http://bitbucket.org/urbanairship/push_sample/

You'll find the server side stuff to be a lot more difficult and for that I would recommend using Urban Airship because we provide a simple RESTful service you can use with lots of add-on features and the indie package is free.

http://urbanairship.com/docs/push_index.html

caveat: I work there.

Steve918