尝试这个:-
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"remote notification: %@",[userInfo description]);
if (userInfo)
{
NSLog(@"%@",userInfo);
if ([[userInfo allKeys] containsObject:@"aps"])
{
if([[[userInfo objectForKey:@"aps"] allKeys] containsObject:@"alert"])
{
NSDictionary *apsDic = [userInfo valueForKey:@"aps"];
NSString *alertStr = [apsDic valueForKey:@"alert"];
NSLog(@"alertstring =%@",alertStr);
NSString *msgStr = [userInfo valueForKey:@"m"];
NSLog(@"messtring= %@",msgStr);
NSNumber *badgeNum = [apsDic valueForKey:@"badge"];
NSLog(@"Badge Number = %@",badgeNum);
if(!isBackGroundMode)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"HEY!"] message:[pushDic objectForKey:@"alert"] delegate:self cancelButtonTitle:@"Luk" otherButtonTitles:@"Læs..",nil];
[alert show];
[alert setTag:1];
[alert release];
}
else
{
[self performSelectorOnMainThread:@selector(directGoToDetalPage) withObject:nil waitUntilDone:NO];
}
}
}
}
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
isBackGroundMode = TRUE;
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
isBackGroundMode = FALSE;
}
#pragma mark
#pragma mark(alertView delegte) Method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag==1)
{
if(buttonIndex == 1)
{
[self performSelectorOnMainThread:@selector(directGoToDetalPage) withObject:nil waitUntilDone:NO];
}
}
}
#pragma mark
#pragma mark(when PushNotification Come) Method
-(void) directGoToDetalPage
{
// where you want to go page............
}
isBackGroundMode
在哪里global variable
。谢谢