Push Notification in Iphone application [closed]

2019-01-16 15:23发布

问题:

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.

回答1:

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.



回答2:

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);

}