触发本地通知时的自定义视图

时间:2013-07-17 13:06:08

标签: ios uilocalnotification alarm

我对Xcode比较陌生,我正在构建一个非常简单的闹钟,下面是应用程序的一小部分。我的问题是:如何在发出警报时显示自定义视图(即图片或动画),并在其上放置“关闭”按钮?提前谢谢

尼古拉

 - (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];

2 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分:0)

如果您的应用位于后台,则可以使用Kalpesh建议。但是,如果您在前景中有应用程序,则无法直接显示自定义视图。您可以显示警报或自定义警报,然后在接受该警报后显示自定义视图。