UILocalNotification点击事件

时间:2012-10-26 05:26:05

标签: iphone ios

我的代码是:

- (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时,我可以来一些视图controller.how要做什么?谢谢

1 个答案:

答案 0 :(得分: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

    }