开发者

How can I generate PushNotification in iPhone?

I'm trying to implement the feature Pushnotification in my app. I have followed the link , I got it working till PushMeBaby app. Got the device token, but I tried with Pu开发者_JS百科shMeBaby, a window with push button came up, when I clicked, nothing happened. Please help me to implement the feature.

EDIT

Me also tried links mentioned in here, from the comments I could see that all are wonderful tutorials.


Make sure you have done the following:

  1. Successfully retrieved and created your SSL certificates for APNS from the Apple Developer Portal

  2. Inserted the correct bundle ID in your app

  3. Created and signed your app with a development certificate that was created using the same App ID that your push notifications are using

  4. Your device token is definitely correct (i.e. xxxxxxxxxxx, no spaces, no dashes, etc., just the characters)

If this is all correct, it should definitely work. I think your problem could possibly be that you are not signing your app with a development certificate linked to your App ID that has push notifications enabled, or your SSL certificates for push notifications have a problem with them. There's a great tutorial here.

By the way, when you do get it working and you're interested in sending push notifications to everyone who has your app (instead of just yourself), I would recommend taking a look at EasyAPNS.


Here is a checklist:

  1. Have you enabled Push Notification of your app from Apple Developer Center?
  2. What is the response from server? Can you get your APNS token?
  3. Is your app using wildcard as Bundle ID? APNS needs your bundle ID non-wildcard.


In following code put into the implementation .m file

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

    //Push notifation Delegate Methods.
    NSLog(@"Registering for push notifications...");    
    [[UIApplication sharedApplication] 
     registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeAlert | 
      UIRemoteNotificationTypeBadge | 
      UIRemoteNotificationTypeSound)];

}

And Implement the Delegate method for the Push notification.

#pragma mark pushnotification

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 


    // Prepare the Device Token for Registration (remove spaces and < >)
    NSString *devToken = [[[[deviceToken description] 
                            stringByReplacingOccurrencesOfString:@"<"withString:@""] 
                           stringByReplacingOccurrencesOfString:@">" withString:@""] 
                          stringByReplacingOccurrencesOfString: @" " withString: @""];


        NSString *str = [NSString 
                         stringWithFormat:@"Device Token=%@",devToken];
        NSLog(@"device token - %@",str);


    REST *rest = [[REST alloc] init];

    [rest resiterForNotification:@selector(notificationRegister_response_arrives:) andHandler:self andToken:devToken];


    [rest autorelease];

}
-(void)notificationRegister_response_arrives:(id)object{
    NSLog(@"%@",object);

    if ([object isKindOfClass:[NSDictionary class]]) {

        if([object valueForKey:@"error"]) {
            NSLog(@"oh!! errors");
        }else {

        }

    }
}


The tutorial I have mentioned in my question is great one. But I couldn't implement on my jailbroken device. But when I tried the same steps on other jailbroken and non-jailbroken iPhone. It was working. So, the error was with my device. When I upgraded the iOS to version 4.3.3, the pushnotification feature was disabled. But was ok when I checked the settings. So I followed the steps in here, I got it working and now I'm getting the notifications.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜