触发本地通知时的自定义视图
Posted
技术标签:
【中文标题】触发本地通知时的自定义视图【英文标题】:custom view when local notification is fired 【发布时间】:2013-07-17 13:06:08 【问题描述】:我对 Xcode 比较陌生,我正在构建一个非常简单的闹钟,下面是应用程序的一个小 sn-p。我的问题是:如何在触发警报时显示自定义视图(即图片或动画),并在其上放置一个“关闭”按钮?提前谢谢你
尼古拉
- (void) scheduleLocalNotificationWithDate:(NSDate *)fireDate :(NSString *)message
UILocalNotification *notificaiton = [[UILocalNotification alloc] init];
if (notificaiton == nil)
return;
notificaiton.fireDate = fireDate;
notificaiton.alertBody = message;
notificaiton.timeZone = [NSTimeZone defaultTimeZone];
notificaiton.alertAction = @"View";
notificaiton.soundName = @"alarm-clock-1.mp3";
notificaiton.applicationIconBadgeNumber = 1;
notificaiton.repeatInterval = kCFCalendarUnitWeekday;
NSLog(@"repeat interval is %@",notificaiton.description);
[[UIApplication sharedApplication] scheduleLocalNotification:notificaiton];
【问题讨论】:
Show an image in the alert body of a local notification的可能重复 【参考方案1】:使用这个方法
在应用运行时处理通知
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
// show your custom alert view
处理从通知启动
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
// show your custom alert view
return YES;
【讨论】:
感谢您的回复,但我不明白...如果相反,我是要显示的图像或动画,我可以简单地将图像名称放在括号中并指定类似 . jpg 等? 我写了评论,即在本节中显示您的自定义警报视图,为您要显示的动画类型执行逻辑 感谢两位,他们是很好的答案。到目前为止,我唯一的问题是我在点击通知后确实看到了我的自定义图像,但它在半秒后消失了。无论如何,谢谢你,两人都欣然接受。【参考方案2】:如果您的应用在后台中,您可以使用建议的 Kalpesh。但是如果您在前台中有应用程序,则不能直接显示自定义视图。您可以显示警报或自定义警报,然后在您接受该警报后显示自定义视图。
【讨论】:
以上是关于触发本地通知时的自定义视图的主要内容,如果未能解决你的问题,请参考以下文章