将UILocalNotifications静音发送一段时间

时间:2016-02-09 10:16:02

标签: ios objective-c iphone cocoa-touch uilocalnotification

我的应用程序每次接近客户的某个商店时都会通知(使用package myApp import grails.gorm.DetachedCriteria import groovy.transform.ToString import org.apache.commons.lang.builder.HashCodeBuilder @ToString(cache=true, includeNames=true, includePackage=false) class UserRole implements Serializable { private static final long serialVersionUID = 1 static constraints = { role validator: { Role r, UserRole ur -> if(ur.user == null || ur.user.id == null) return boolean existing = false UserRole.withNewSession { existing = UserRole.exists(ur.user.id, r.id) } if(existing) { return 'userRole.exists' } } } static mapping = { id composite: ['user', 'role'] version false } User user Role role /*UserRole(User u, Role r) { this() user = u role = r }*/ @Override boolean equals(other) { if(!(other instanceof UserRole)) { return false } other.user?.id == user?.id && other.role?.id == role?.id } @Override int hashCode() { def builder = new HashCodeBuilder() if(user) builder.append(user.id) if(role) builder.append(role.id) builder.toHashCode() } static UserRole get(long userId, long roleId) { criteriaFor(userId, roleId).get() } static boolean exists(long userId, long roleId) { criteriaFor(userId, roleId).count() } private static DetachedCriteria criteriaFor(long userId, long roleId) { UserRole.where { user == User.load(userId) && role == Role.load(roleId) } } static UserRole create(User user, Role role, boolean flush = false) { def instance = new UserRole(user: user, role: role) instance.save(flush: flush, insert: true) instance } static boolean remove(User u, Role r, boolean flush = false) { if(u == null || r == null) return false int rowCount = UserRole.where { user == u && role == r }.deleteAll() if(flush) { UserRole.withSession { it.flush() } } rowCount } static void removeAll(User u, boolean flush = false) { if(u == null) return UserRole.where { user == u }.deleteAll() if(flush) { UserRole.withSession { it.flush() } } } static void removeAll(Role r, boolean flush = false) { if(r == null) return UserRole.where { role == r }.deleteAll() if(flush) { UserRole.withSession { it.flush() } } } } )用户,即使是在后台也是如此。

我有一个静音按钮,当用户点击时,一个actionSheet会弹出并询问他要将该应用程序静音多长时间(5小时,24小时,1周或1个月)。

当用户选择其中一个选项时,我希望应用停止发送通知,直到此时间过去。

这样做的最佳方式是什么?

我真的很感谢代码示例。

谢谢!

1 个答案:

答案 0 :(得分:0)

//fire local notification 

    NSDate * storedDate // Store your date when setting the mute 
    int tillHoursForMute // hours for mute

    muteDate  = <storedDate+tillHoursForMute> //concatenate the hours into date
   if ([muteDate compare:firingDate] == NSOrderedDescending && [muteDate compare:firingDate] == NSOrderedAscending) {
    //fire Notification        

   } else {
      //Mute time

  }    

注意:只需编写步骤,根据语言位置进行更改。