核心数据中的数据更新时的本地通知?

时间:2012-10-04 09:08:46

标签: iphone uilocalnotification

我有一个应用程序,通过检查数据是否存在的谓词,从网站和seva中检索数据到核心数据。如果没有保存到核心数据。如果是,则更新旧的。我需要在插入新数据时发出本地通知。我能这样做吗?有什么想法吗?

非常感谢

2 个答案:

答案 0 :(得分:0)

您可以使用

在当前时间点火通知

localNotification.fireDate = [NSDate date];

关注本地非小说Link

的苹果文档

localNotification Link

的示例代码

我的代码

-(IBAction)localNotificationBtnPress:(id)sender
{
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];

    if (!localNotification) 
        return;

    // Current date
    NSDate *date = [NSDate date]; 


    // Add one minute to the current time
    NSDate *dateToFire = [date dateByAddingTimeInterval:5];

    NSLog(@"local noti fire date...>> %@",dateToFire);

    // Set the fire date/time
    [localNotification setFireDate:dateToFire];
    [localNotification setTimeZone:[NSTimeZone defaultTimeZone]];

    // Setup alert notification
    [localNotification setAlertAction:@"Open App"];
    [localNotification setAlertBody:@"Notification hiiiiiiiiiiiiii" ];
    localNotification.soundName=UILocalNotificationDefaultSoundName;
    [localNotification setHasAction:YES];      

    UIApplication *app=[UIApplication sharedApplication];

     [app scheduleLocalNotification:localNotification];
}

答案 1 :(得分:0)

if (newRecord)
{
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {
        NSString *kRemindMeNotificationDataKey = @"kRemindMeNotificationDataKey";

        UILocalNotification *notification = [[cls alloc] init];

        notification.fireDate = [NSDate date];
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.alertBody = [NSString stringWithFormat:@"Record Inserted"];
        notification.alertAction = @"Show me";
        notification.soundName = UILocalNotificationDefaultSoundName;
        notification.applicationIconBadgeNumber = 1;
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:yourObjectorString forKey:kRemindMeNotificationDataKey];
        notification.userInfo = userDict;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        [notification release];
    }
}

我希望这可以帮到你..

:)