4

我的代码是:

- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet
{
NSLog(@"didReceiveEvent(),%@",packet.data );



SysNotification *sysNotification=[GlobalVariable parseSysNotificationWithString:packet.data];


UILocalNotification *alarm = [[UILocalNotification alloc] init];
if (alarm) {
    alarm.fireDate = [NSDate date];
    alarm.timeZone = [NSTimeZone defaultTimeZone];
    alarm.repeatInterval = 0;
    alarm.soundName = UILocalNotificationDefaultSoundName;
    alarm.alertBody = @"Test message...";

    NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
    alarm.userInfo = infoDic;


    [[UIApplication sharedApplication] presentLocalNotificationNow:alarm];
}


}

我想当我点击状态栏上的 UILocalNotification 时,我可以来一些视图控制器。怎么办?谢谢

4

1 回答 1

5

有两种情况来处理本地通知,

1. 应用程序因点击本地通知而启动

-(BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UILocalNotification *localNotif =

        [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

    if (localNotif) {

       //load your controller

    }

    return YES;

}

2.应用程序处于活动状态,然后在AppDelegate中添加此代码

   -(void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {

        //load your controller

    }
于 2012-10-26T05:32:02.927 回答