我已经通过uilocalnotifications.so设置了一个闹钟当我的应用程序在后台我的本地通知显示与2按钮关闭和view.when我的应用程序在前台它显示和alertview与2个按钮,停止和贪睡。当单击停止按钮时,我希望我的闹钟应该停止,当点击贪睡按钮时,我希望通知应该在5分钟后出现。这是可能的。请帮助我解决这个概率。谢谢。如何调用按钮上的贪睡功能点击alertview
this is my code :
//this is my controller class where i am setting my notification
- (void)clearNotification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
- (void)scheduleNotification {
[reminderText resignFirstResponder];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"Did you forget something?";
notif.alertAction = @"Show me";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
NSInteger index = [scheduleControl selectedSegmentIndex];
switch (index) {
case 1:
notif.repeatInterval = NSMinuteCalendarUnit;
break;
case 2:
notif.repeatInterval = NSHourCalendarUnit;
break;
case 3:
notif.repeatInterval = NSDayCalendarUnit;
break;
case 4:
notif.repeatInterval = NSWeekCalendarUnit;
break;
default:
notif.repeatInterval = 0;
break;
}
NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text
forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
}
#pragma mark -
#pragma mark === Public Methods ===
#pragma mark -
- (void)showReminder:(NSString *)text {
if (reminderText != nil) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Reminder"
message:text delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"stop",@"Snooze",nil];
[alertView show];
[alertView release];
}
}
//this is my appdelegate where i am receiving my notification
- (void)clearNotification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
- (void)scheduleNotification {
[reminderText resignFirstResponder];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"Did you forget something?";
notif.alertAction = @"Show me";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
NSInteger index = [scheduleControl selectedSegmentIndex];
switch (index) {
case 1:
notif.repeatInterval = NSMinuteCalendarUnit;
break;
case 2:
notif.repeatInterval = NSHourCalendarUnit;
break;
case 3:
notif.repeatInterval = NSDayCalendarUnit;
break;
case 4:
notif.repeatInterval = NSWeekCalendarUnit;
break;
default:
notif.repeatInterval = 0;
break;
}
NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text
forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
}
#pragma mark -
#pragma mark === Public Methods ===
#pragma mark -
- (void)showReminder:(NSString *)text {
if (reminderText != nil) {
/*newtest *new = [[newtest alloc]initWithNibName:@"newtest" bundle:nil];
[self.navigationController pushViewController:new animated:YES];
[new release];*/
// - (void)alertView:(UIAlertView *)alert
// didDismissWithButtonIndex:(NSInteger) buttonIndex
// {
// if (buttonIndex == 0)
// {
// NSLog(@"Cancel Tapped.");
// }
// else if (buttonIndex == 1)
// {
// NSLog(@"OK Tapped. Hello World!");
// }
// }
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Reminder"
message:text delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"stop",@"Snooze",nil];
[alertView show];
[alertView release];
}
}
- (无效)alertView:(UIAlertView中*)alertView clickedButtonAtIndex:(NSInteger的)buttonIndex
{
的NSString *标题= [alertView buttonTitleAtIndex:buttonIndex];
if(buttonIndex == 0)
{
NSLog(@"Button 1 was selected.");
}
else if([title isEqualToString:@"Button 2"])
{
NSLog(@"Button 2 was selected.");
}
}
//this is my appdelegate where i am receiving notification
NSString *kRemindMeNotificationDataKey = @"kRemindMeNotificationDataKey";
#pragma mark -
#pragma mark === Application Delegate Methods ===
#pragma mark -
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Class cls = NSClassFromString(@"UILocalNotification");
if (cls) {
UILocalNotification *notification = [launchOptions objectForKey:
UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
NSString *reminderText = [notification.userInfo
objectForKey:kRemindMeNotificationDataKey];
[viewController showReminder:reminderText];
/*newtest *new = [[newtest alloc]initWithNibName:@"newtest" bundle:nil];
[window addSubview:new.view];*/
}
}
application.applicationIconBadgeNumber = 0;
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
application.applicationIconBadgeNumber = 0;
}
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
// UIApplicationState state = [application applicationState];
// if (state == UIApplicationStateInactive) {
// Application was in the background when notification
// was delivered.
// }
application.applicationIconBadgeNumber = 0;
NSString *reminderText = [notification.userInfo
objectForKey:kRemindMeNotificationDataKey];
[viewController showReminder:reminderText];
NSLog(@"Recieved Notification %@",notification);
}
罗恩,我得到完全confused.Please u能提供关于如何调用该加5分钟firedate另一个函数的一些演示代码。 – Rocky