Skip to content

Instantly share code, notes, and snippets.

@smartweb
Last active August 29, 2015 13:57
Show Gist options
  • Save smartweb/9546845 to your computer and use it in GitHub Desktop.
Save smartweb/9546845 to your computer and use it in GitHub Desktop.
添加本地通知
def add_local_notification
local_noti = UILocalNotification.alloc.init
return if local_noti.nil?
NSLog("添加本地消息通知")
now = NSDate.now
# 触发通知的时间
local_noti.fireDate = now.dateByAddingTimeInterval(10)
# 循环次数,kCFCalendarUnitWeekday一周一次
local_noti.repeatInterval =0
# local_noti.timeZone = NSTimeZone.defaultTimeZone
local_noti.alertBody = "亲,快来称一下吧"
local_noti.alertAction = "瘦不下,不成活"
local_noti.soundName = UILocalNotificationDefaultSoundName
local_noti.applicationIconBadgeNumber = 1
# NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
# local_noti.userInfo = infoDict;
UIApplication.sharedApplication.scheduleLocalNotification(local_noti)
end
# AppDelegate里设置接收消息
def application(application, didReceiveLocalNotification:notification)
App.alert(notification.alertBody)
# NSDictionary* dic = [[NSDictionary alloc]init];
# //这里可以接受到本地通知中心发送的消息
# dic = notification.userInfo;
# NSLog(@"user info = %@",[dic objectForKey:@"key"]);
# 图标上的数字减1
application.applicationIconBadgeNumber -= 1
end
def applicationWillResignActive(application)
# 图标上的数字减1
application.applicationIconBadgeNumber -= 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment