iOS Unable to get deviceToken

rahulvyas

macrumors newbie
Original poster
May 6, 2009
20
0
I want to use push notification in my app.I have created an unique app id and created push development certificate.also created provisioning profile using that unique app id.I put the code for registering the device in application terminate method so that when my app closed it's enabled push notification and when it launches it disables the push notification.BTW currently i am using ApplicationDidFnishLaunching method and registering for push notification.The app is registered for push notification i think because it asks to allow push notification on alertview.But i've never found device token.The app is not invoking the method
Code:

Code:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
	NSLog(@"devToken=%@",deviceToken);
	[self alertNotice:@"" withMSG:[NSString stringWithFormat:@"devToken=%@",deviceToken] cancleButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitle:@""];
}
even i set a breakpoint in this method but it's not invoking.
i have iPhone 3GS jailbroken. Anybody knows why i'm not getting devicetoken.
 

rahulvyas

macrumors newbie
Original poster
May 6, 2009
20
0
here is what i have put in appdelegate
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {	
    // Override point for customization after application launch
	BOOL result=application.enabledRemoteNotificationTypes;
	if(result)
	{
		[[UIApplication sharedApplication] unregisterForRemoteNotifications];
	}
	else
	{
		//Register for notifications
		[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
		[self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitle:@""];
		
	}
	[window setBackgroundColor:[UIColor colorWithRed:96/256.0 green:143/256.0 blue:191/256.0 alpha:.8]];
	[window addSubview:[viewController view]];
    [window makeKeyAndVisible];
	
}

// Delegation methods 
- (void)application:(UIApplication *)app 
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken { 
    const void *devTokenBytes = [devToken bytes];
	NSLog(@"devToken=%@",devTokenBytes);
	[self alertNotice:@"" withMSG:[NSString stringWithFormat:@"devToken=%@",devTokenBytes] cancleButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitle:@""];
	
	
}

- (void)application:(UIApplication *)app 
didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    NSLog(@"Error in registration. Error: %@", err); 
	[self alertNotice:@"" withMSG:[NSString stringWithFormat:@"Error in registration. Error: %@", err] cancleButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitle:@""];

}
	 
-(void)alertNotice:(NSString *)title withMSG:(NSString *)msg cancleButtonTitle:(NSString *)cancleTitle otherButtonTitle:(NSString *)otherTitle{
	 UIAlertView *alert;
	 if([otherTitle isEqualToString:@""])	 
		 alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:nil,nil];
	 else
		 alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:otherTitle,nil];
	 [alert show];
	 [alert release];
}
 
Comment

rahulvyas

macrumors newbie
Original poster
May 6, 2009
20
0
Log shows nothing but i get this alert when my view loads

Code:
[self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitle:@""];
and settings for push notification appears in settings app.

and when i unregistered settings removed from settings app.

also tell me if this possible "enable notification when app terminates and disable when app launches".
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.