OStack程序员社区-中国程序员成长平台

标题: ios - 触发本地通知时的自定义 View [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:34
标题: ios - 触发本地通知时的自定义 View

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

尼古拉

 - (void) scheduleLocalNotificationWithDateNSDate *)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];



Best Answer-推荐答案


使用这个方法

Handle the notificaton when the app is running

- (void)applicationUIApplication *)app didReceiveLocalNotificationUILocalNotification *)notif 
{
// show your custom alert view
}

Handle launching from a notification

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions {

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

return YES;
}

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






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4