ios - 触发本地通知时的自定义 View

标签 ios uilocalnotification alarm

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

尼古拉

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

最佳答案

使用这个方法

Handle the notificaton when the app is running

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif 
{
// show your custom alert view
}

Handle launching from a notification

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) 
{
// show your custom alert view
}

return YES;
}

关于ios - 触发本地通知时的自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17700606/

相关文章:

ios从另一个 Controller 中删除 subview

ios - 将披露按钮添加到 MKPointAnnotation

ios - 在本地设置图标角标(Badge)编号是否需要 iOS 中的用户权限?

ios - 应用程序在后台运行时发送本地通知 Swift 2.0

android - 如何将数据从 BroadcastReceiver 传递到正在启动的 Activity?

ios - 推送通知不起作用 Xcode 11.3.1

ios - 使用动态高度和全高创建不同的单元尺寸

ios - UILocalNotifications 触发时没有声音

Python线程以精确的时间间隔执行

android - 计算Android闹钟的时间