如果用户在iPhone SDK中取消UILocaNotification警报,则执行方法

时间:2011-12-08 07:30:37

标签: iphone objective-c uilocalnotification

我是iphone编程的新手。我在我的应用程序中使用localNotification。它正在向用户发出警报并使用didReceiveLocalNotification响应Launch.But我的问题是如果用户关闭我的应用程序中的UILocalNotification我需要执行数据库操作。那我怎么能这样做。是否有任何接近那个。

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    NSDate* now = [NSDate date];
    [localNotification setFireDate:now];
    localNotification.soundName=@"Tink.wav";

    [localNotification setAlertAction:@"Launch"]; 
    [localNotification setAlertBody:@"You have entered to Your Place:"]; 
    [localNotification setHasAction: YES]; 
    NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"obj" forKey:kRemindMeNotificationDataKey];
    localNotification.userInfo = userDict;



- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    NSLog(@"Recieved Notification");

    NSString *DateString=[notif.userInfo valueForKey:kRemindMeNotificationDataKey];
    if([DateString isEqualToString:@"obj"])
    { 
        [[UIApplication sharedApplication] cancelLocalNotification:notif];
    }

    NSString *strNotif=[notif.userInfo objectForKey:kRemindMeNotificationDataKey];
if ([strNotif isEqualToString:@"obj"]) {
    UIAlertView *alretCheck=[[UIAlertView alloc]initWithTitle:@"notifi Testing in DidRec+" message:strNotif  delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alretCheck show];
    [alretCheck release];
}

提前感谢你。

1 个答案:

答案 0 :(得分:3)

现在Acc。根据我的知识,我们无法做到你想要的。我们只对LocalNotification Alert的“View”选项有命令。但是如果可能的话,你可以做一件事点击“查看”按钮你可以显示一个ActionSheet或另一个警告,在这些按钮上你可以处理你想要的所有事件。