English 中文(简体)
如何确定发射的自建当地通知的固定日期?
原标题:how to set uilocalnotification firedate for a fixed date?
  • 时间:2011-05-21 06:06:43
  •  标签:
  • iphone

i 想就下午6时开始的方案提出当地通知。 也就是说,在日期变量中需要时间,而且正将其与现行系统日期进行比较。

Say setDate is for fixed date i.e 6.00 pm so i have to set firedate such that it shows the notification before 30 mintes the program starts. The examples i have seen in that the firedate is set according to currentdate.

Can someone tell me how can i set firedate according to my fixed date??

最佳回答

Well then you can handle your local notification in application delegate file when ever you get the notification. e.g. here is the delegate method which is fired everytime when you get the local notification.

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    //Handle the notificaton when the app is running
    NSLog(@"Recieved Notification %@",notif);


        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hey Neha" message:@"Sanjay wants to be your friend " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alertView show];
        [alertView release];

        SystemSoundID bell;  
        AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"WhoopFlp" ofType:@"wav"]], &bell);  
        AudioServicesPlaySystemSound (bell);

        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

        i=0;
    }
}

So what I am doing here is simply showing the alert and playing a system sound when my local notification occurs. So now what you want is to navigate to the page in the program where you were when you get the local notification.So simply in this delegate method you need to allocate your view controller and need to push the view controller to that view where you want to be. That would solve your problem. Well i had a similar kind of problem what i wanted is to show the notification in the background and in the front end as well, so writing the 2 different methods in my app was not worthful.so i handled it this way in the delegate method which will show the notification in the front end as well. Good luck to you.

问题回答

您以这种方式向当地发出通知

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
         if (localNotif == nil)
         return;
         localNotif.fireDate = [NSDate date];// Now here you can manage the fire time.
         localNotif.timeZone = [NSTimeZone defaultTimeZone];
         // Notification details
         localNotif.alertBody = @"BusBuddy";
         // Set the action button
         localNotif.alertAction = @"View";
         localNotif.soundName = UILocalNotificationDefaultSoundName;
         localNotif.applicationIconBadgeNumber = 1;
         // Specify custom data for the notification
         NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"You are near to reach the Bus Stop" forKey:@"someKey"];
         localNotif.userInfo = infoDict;
         // Schedule the notification
         [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
         [localNotif release];

这一法典将适用于你。 你只是需要为此提供日期。

localNotif.fireDate = [NSDate date];

现在,为了安排你的日期,你可以提及这些联系。

localnotification =[[UILocalNotification alloc]init];
[localnotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:[lodatepicker countDownDuration]]];
[localnotification setAlertAction:@"Launch"];
[localnotification setHasAction: YES];
[localnotification setAlertBody:[lotextview text]];
// [localnotification setSoundName:musicString];
localnotification.timeZone = [NSTimeZone defaultTimeZone];
[localnotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
[[UIApplication sharedApplication] scheduleLocalNotification:localnotification];




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签