0

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

非常感谢

4

2 回答 2

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];
    }
}

我希望这对你有帮助..

:)

于 2012-10-04T09:23:11.623 回答
0

您可以使用当前时间触发通知

localNotification.fireDate = [NSDate date];

关注本地非小说类链接的苹果文档

localNotification链接的示例代码

我的代码

-(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];
}
于 2012-10-04T09:17:53.603 回答