cocos2d-x 添加本地通知UILocalNotification
2012-04-09 10:50
330 查看
猴子原创,欢迎转载!转载请注明出处,谢谢!
原文地址:http://blog.csdn.net/yanghuiliu/article/details/7439917
本地通知UILocalNotification现在被大量用在游戏设计中,目的在于召回用户。一个合理的通知提示,或许能让用户重新回到你的游戏中,那么如何在cocos2d-x中添加本地通知呢?
其实很简单,打开ios目录下的AppController.mm文件,在application函数最下方添加如下代码,最后结果如下:
这里方便看效果,我把首次触发的时间写成15秒,这样程序运行后,按Home键退到主屏幕,等15秒就可以看到效果了。
要同时启动多个通知,只需要注册多个就行了。
原文地址:http://blog.csdn.net/yanghuiliu/article/details/7439917
本地通知UILocalNotification现在被大量用在游戏设计中,目的在于召回用户。一个合理的通知提示,或许能让用户重新回到你的游戏中,那么如何在cocos2d-x中添加本地通知呢?
其实很简单,打开ios目录下的AppController.mm文件,在application函数最下方添加如下代码,最后结果如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the view controller's view to the window and display. //........ application.applicationIconBadgeNumber = 0;//应用程序右上角的数字=0(消失) [[UIApplication sharedApplication] cancelAllLocalNotifications];//取消所有的通知 //------通知; UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notification!=nil) {//判断系统是否支持本地通知 NSDate *now=[NSDate new]; // notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:kCFCalendarUnitDay];//本次开启立即执行的周期 notification.fireDate=[now addTimeInterval:15];//本次开启立即执行的周期 notification.repeatInterval=kCFCalendarUnitMinute;//循环通知的周期 notification.timeZone=[NSTimeZone defaultTimeZone]; notification.alertBody=@"猴哥,要吃饭啦!";//弹出的提示信息 notification.applicationIconBadgeNumber=1; //应用程序的右上角小数字 notification.soundName= UILocalNotificationDefaultSoundName;//本地化通知的声音 notification.alertAction = NSLocalizedString(@"去吃饭", nil); //弹出的提示框按钮 [[UIApplication sharedApplication] scheduleLocalNotification:notification]; } //本地通知 end return YES; }
这里方便看效果,我把首次触发的时间写成15秒,这样程序运行后,按Home键退到主屏幕,等15秒就可以看到效果了。
要同时启动多个通知,只需要注册多个就行了。
相关文章推荐
- cocos2d-x 添加本地通知UILocalNotification
- cocos2d-x 添加本地通知UILocalNotification
- 使用UILocalNotification给App添加本地消息通知
- 使用UILocalNotification 添加本地通知事件
- 【iOS-Cocos2d游戏开发之十六】添加本地通知(UILocalNotification)以及添加系统组件滚动视图(UIScrollView)!【2011年11月15日更新】
- cocos2d游戏添加本地通知
- 【iOS-Cocos2d游戏开发之十六】添加本地通知(UILocalNotification)以及添加系统组件滚动视图(UIScrollView)!【2011年11月15日更新】
- 【Cocos2d游戏开发之十六】添加本地通知(UILocalNotification)以及添加系统组件滚动视图(UIScrollView)! 推荐
- 【iOS开发-119】ipa打包、单元测试test、本地通知UILocalNotification
- 本地通知UILocalNotification
- 本地通知UILocalNotification
- ios推送:本地通知UILocalNotification
- 添加本地通知(UILocalNotification)以及添加系统组件滚动视图(UIScrollView)
- iOS本地通知UILocalNotification
- ios推送:本地通知UILocalNotification
- UILocalNotification 本地通知无法删除的坑
- iOS UILocalNotification 多个本地通知,怎么有区分的删除
- iOS学习笔记45—本地通知UILocalNotification
- UILocalNotification本地通知01
- iOS开发之本地通知UILocalNotification