I am sending push notification on device which has iOS 5.0.1, but notification is not received on iOS5 device.
If i try to send notification on iOS4.3.3 device, it received on this device.
My server is developed in c# and apple push notification certificate is used in .p12 format.
My code to register the notification is
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Set the navigation controller as the window's root view controller and display.
deviceToken = nil;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] enabledRemoteNotificationTypes];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
{
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Succeeded in registering for APNS" message:@"Sucess" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
[alertView release];
deviceToken = [devToken retain];
NSMutableString *dev = [[NSMutableString alloc] init];
NSRange r;
r.length = 1;
unsigned char c;
for (int i = 0; i < [deviceToken length]; i++)
{
r.location = i;
[deviceToken getBytes:&c range:r];
if (c < 10) {
[dev appendFormat:@"0%x", c];
}
else {
[dev appendFormat:@"%x", c];
}
}
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setObject:dev forKey:@"DeviceToken"];
[def synchronize];
NSLog(@"Registered for APNS %@\n%@", deviceToken, dev);
[dev release];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Failed to register %@", [error localizedDescription]);
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"FAILED" message:@"Fail" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
[alertView release];
deviceToken = nil;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Recieved Remote Notification %@", userInfo);
NSDictionary *aps = [userInfo objectForKey:@"aps"];
NSDictionary *alert = [aps objectForKey:@"alert"];
//NSString *actionLocKey = [alert objectForKey:@"action-loc-key"];
NSString *body = [alert objectForKey:@"body"];
// NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];
//
// if ([viewControllers count] > 2) {
// NSRange r;
// r.length = [viewControllers count] - 2;
// r.location = 2;
// [viewControllers removeObjectsInRange:r];
//
// MapViewController *map = (MapViewController*)[viewControllers objectAtIndex:1];
// [map askDriver];
// }
//
// [self.navigationController setViewControllers:viewControllers];
// [viewControllers release];
//NewBooking,"BookingId",Passenger_latitude,Passenger_longitude,Destination_latitude,Destination_longitude,Distance,Time,comments
NSArray *arr = [body componentsSeparatedByString:@","];
if ([arr count]>0) {
MapViewController *map = (MapViewController*)[[self.navigationController viewControllers] objectAtIndex:1];
[map askDriver:arr];
[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:1] animated:YES];
}
//NSString *sound = [userInfo objectForKey:@"sound"];
//UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:actionLocKey
// message:body delegate:nil
// cancelButtonTitle:@"Reject"
// otherButtonTitles:@"Accept", nil];
//
// [alertV show];
// [alertV release];
}
Can anyone help me out with this issue. Why notification received on iOS4.3 device but not on iOS5?
Thank you very much!!! in advance