草庐IT

iphone - 每天下午 5 点重复 UILocalNotification

coder 2024-01-15 原文

如何每天下午 5 点重复 UILocalNotification?以下是我设置自定义时间的代码。但我想每天在自定义时间或可能是静态时间通知用户。我正在使用 iOS 6。

    -(void)scheduleNotification{

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 [dateFormatter setDateFormat:@"h:mm a"];
NSDate *dateFromString = [[NSDate alloc] init];

dateFromString = [dateFormatter dateFromString:timeStr];

UILocalNotification *localNotif = [[UILocalNotification alloc] init];

if (localNotif == nil)
    return;


localNotif.fireDate = dateFromString;

localNotif.repeatInterval = kCFCalendarUnitDay;
localNotif.timeZone = [NSTimeZone defaultTimeZone];

// Notification details
localNotif.alertBody = @"Reminder is set";
// Set the action button
localNotif.alertAction = @"Ok";

localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;

// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Local Push received while running", @"key", nil];
localNotif.userInfo = infoDict;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

}

最佳答案

使用这个。可能对你有帮助

NSDateFormatter *dat= [[NSDateFormatter alloc]init];
[dat setLocale:[NSLocale currentLocale]];
[dat setTimeZone:[NSTimeZone systemTimeZone]];

//[dat setDateFormat:@"YYYY-MM-dd"];// YYYY-MM-dd hh:mm a
//NSString *dateM=[dat stringFromDate:datM];
//[dat setDateFormat:@"YYYY-MM-dd h:mm a"];
NSDate *reminderDate=[NSDate date];
reminderDate =[reminderDate dateByAddingTimeInterval:1*24*60*60];

UILocalNotification  *missingDreamNotify=[[UILocalNotification alloc]init];
missingDreamNotify.fireDate=reminderDate;
missingDreamNotify.timeZone = [NSTimeZone defaultTimeZone];
missingDreamNotify.alertBody = @"Reminder is set";
missingDreamNotify.alertAction = @"Show me";
missingDreamNotify.soundName = UILocalNotificationDefaultSoundName;
missingDreamNotify.applicationIconBadgeNumber = 1;
missingDreamNotify.repeatInterval = NSDayCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:missingDreamNotify];

关于iphone - 每天下午 5 点重复 UILocalNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13156166/

有关iphone - 每天下午 5 点重复 UILocalNotification的更多相关文章

  1. ruby - 正则表达式 - 保存重复捕获的组 - 2

    这就是我做的a="%span.rockets#diamonds.ribbons.forever"a=a.match(/(^\%\w+)([\.|\#]\w+)+/)putsa.inspect这是我得到的#这就是我想要的#帮助?我尝试过但失败了:( 最佳答案 通常,您不能获得任意数量的捕获组,但如果您使用扫描,您可以为您想要捕获的每个标记获得一个匹配:a="%span.rockets#diamonds.ribbons.forever"a=a.scan(/^%\w+|\G[.|#]\w+/)putsa.inspect["%span","

  2. ruby-on-rails - 使用 Ruby 标准 Logger 每天只创建一个日志 - 2

    我正在使用ruby​​标准记录器,我想要每天轮换一次,所以在我的代码中我有:Logger.new("#{$ROOT_PATH}/log/errors.log",'daily')它运行完美,但它创建了两个文件errors.log.20130217和errors.log.20130217.1。如何强制它每天只创建一个文件? 最佳答案 您的代码对于长时间运行的应用程序是正确的。发生的事情是您在给定的一天多次运行代码。第一次运行时,Ruby会创建一个日志文件“errors.log”。当日期改变时,Ruby将文件重命名为“errors.log

  3. Ruby 从数组中删除重复的对象 - 2

    我无法使用传统的Ruby方法从下面的数组user_list中删除所有重复对象,从而获得预期的结果。有解决这个问题的聪明方法吗?users=[]user_list.eachdo|u|user=User.find_by_id(u.user_id)users 最佳答案 这个怎么样?users=User.find(user_list.map(&:user_id).uniq)这具有作为一个数据库调用而不是user_list.size数据库调用的额外好处。 关于Ruby从数组中删除重复的对象,我们在

  4. Ruby 删除可枚举列表中的重复项 - 2

    ruby中有没有一个很好的方法来删除可枚举列表中的重复项(即拒绝等) 最佳答案 对于数组你可以使用uniq()方法a=["a","a","b","b","c"]a.uniq#=>["a","b","c"]所以如果你只是(1..10).to_a.uniq或%w{antbatcatant}.to_a.uniq因为无论如何,几乎所有您实现的方法都将作为Array类返回。 关于Ruby删除可枚举列表中的重复项,我们在StackOverflow上找到一个类似的问题: h

  5. ruby - 重复排列 - 2

    我知道如何创建值数组的排列。例如:[*1..3].permutation(2)这导致以下六种排列:[1,2][1,3][2,1][2,3][3,1][3,2]但这个结果缺少三个排列,它们是相同值的组合,即:[1,1][2,2][3,3]如何获得所有排列,包括上面重复的排列? 最佳答案 尝试#repeated_permutation:[*1..3].repeated_permutation(3).to_a>pp[*1..3].repeated_permutation(3).to_a[[1,1,1],[1,1,2],[1,1,3],[1

  6. ruby - 在 Ruby 数组中收集重复项的最快/单行方法? - 2

    像这样转换数组的最快/单行方法是什么:[1,1,1,1,2,2,3,5,5,5,8,13,21,21,21]...进入像这样的对象数组:[{1=>4},{2=>2},{3=>1},{5=>3},{8=>1},{13=>1},{21=>3}] 最佳答案 要获得所需的格式,您可以附加一个调用以映射到您的解决方案:array.inject({}){|h,v|h[v]||=0;h[v]+=1;h}.map{|k,v|{k=>v}}虽然它仍然是单行的,但它开始变得凌乱了。 关于ruby-在Ruby

  7. ruby-on-rails - 从 ruby​​ 中的数组中删除重复项 - 2

    我想输出一个散列数组,其中name对所有散列都是唯一的。我将如何使用ruby​​执行此操作?这是我的输入:input=[{:name=>"Kutty",:score=>2,:some_key=>'value',...},{:name=>"Kutty",:score=>4,:some_key=>'value',...},{:name=>"Baba",:score=>5,:some_key=>'value',...}]我希望输出看起来像这样:output=[{:name=>"Kutty",:score=>4,:some_key=>'value',...},{:name=>"Baba",:s

  8. sql - Rails:使用 Postgres 创建对象时重复 ActiveRecord::RecordNotUnique? - 2

    我正在使用Rails4应用程序,它需要创建大量对象以响应来自另一个系统的事件。当我调用create!时,主键列上出现非常频繁的ActiveRecord::RecordNotUnique错误(由PG::UniqueViolation引起)我的模型之一。我在SO上找到了其他答案,建议挽救异常并调用retry:beginTableName.create!(data:'here')rescueActiveRecord::RecordNotUnique=>eife.message.include?'_pkey'#Onlyretryprimarykeyviolationslog.warn"Retr

  9. ruby-on-rails - Ruby 和 SQL 中的重复业务逻辑 - 2

    我有一个PORO(普通旧Ruby对象)来处理一些业务逻辑。它接收一个ActiveRecord对象并对其进行分类。为了简单起见,以下面为例:classClassificatorSTATES={1=>"Positive",2=>"Neutral",3=>"Negative"}definitializer(item)@item=itemenddefnameSTATES.fetch(state_id)endprivatedefstate_idreturn1if@item.value>0return2if@item.value==0return3if@item.value但是,我还想根据这些st

  10. ruby - 如何更优雅地删除 Ruby 数组所有元素中的重复项? - 2

    我想删除Array对象中的重复项目。最好举例说明。我有以下数组entries=["abc","ab","c","cd"]我想要一种方法,通过从Array中的元素中删除重复项来清理它,并返回一个Array,每个唯一项都有一个元素。所以这是我为此编写的方法:classArraydefclean_up()self.join("").split("").uniqendend所以现在当我调用entries.clean_up时,我得到以下结果:["a","b","c","d"]这正是我想要的结果,但是在Ruby中有更优雅的方法吗? 最佳答案 s

随机推荐