gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:02 25 4
gpt4 key购买 nike

我对 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com