簡體   English   中英

在ios7中隱含特定日期的本地通知

[英]Impliment local notification for specific day in ios7

我有兩個表視圖,每個索引的字典都有不同的NSMutableArray有一個NSString格式的日期字段。 現在我的問題是,當用戶使用選擇器視圖設置時間而不是每天(如果當天有可用記錄)時,他會在同一時間收到local notification 我不知道如何執行此操作,請幫助我..謝謝

在您的情況下,您需要將fireDate設置為通知將到達的日期/時間,並設置repeatInterval來描述通知的重復。 在這里,您需要設置kCFCalendarUnitDay因為您想每天重復一次通知。

重復單元:

NSEraCalendarUnit
NSYearCalendarUnit
NSMonthCalendarUnit
NSDayCalendarUnit
NSHourCalendarUnit
NSMinuteCalendarUnit
NSSecondCalendarUnit
NSWeekCalendarUnit
NSWeekdayCalendarUnit
新南威爾士州平日有序日歷單元
NSQuarterCalendarUnit

有關更多信息,有一些SO問題。

每天下午5點重復UILocalNotification
iPhone:每日本地通知
http://useyourloaf.com/blog/2010/09/13/repeating-an-ios-local-notification.html

在AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
  return YES;
 }

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{    
  UIAlertView *notificationAlert = [[UIAlertView alloc] initWithTitle:@"Notification"    message:@"This local notification" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
  [notificationAlert show];
   // NSLog(@"didReceiveLocalNotification");
}

將此代碼以.m文件格式發送到您的ViewController中:

-(IBAction)startLocalNotification 
{  
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setDateFormat:@"h:mm a"];
  NSDate *dateFromString = [[NSDate alloc] init];
  dateFromString = [dateFormatter dateFromString:timeStr];

  NSLog(@"startLocalNotification");    
  UILocalNotification *notification = [[UILocalNotification alloc] init];
  notification.fireDate = dateFromString;
  notification.repeatInterval = NSDayCalendarUnit;
  notification.alertBody = @"This is local notification!";
  notification.timeZone = [NSTimeZone defaultTimeZone];
  notification.soundName = UILocalNotificationDefaultSoundName;
  notification.applicationIconBadgeNumber = 10;
  [[UIApplication sharedApplication] scheduleLocalNotification:notification];    
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM