gpt4 book ai didi

iphone - iOS - 后台本地通知

转载 作者:行者123 更新时间:2023-11-29 10:55:21 25 4
gpt4 key购买 nike

我在文件 ViewController.m 中设置通知后遇到问题

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

NSDateComponents *componentsForReferenceDate = [calendar components:(NSDayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit ) fromDate:[NSDate date]];

[componentsForReferenceDate setDay: 9];
[componentsForReferenceDate setMonth: 11];
[componentsForReferenceDate setYear: 2012];

NSDate *referenceDate = [calendar dateFromComponents:componentsForReferenceDate];

// IMPOSTO ORA NOTIFICA

NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit ) fromDate: referenceDate];

[componentsForFireDate setHour: 19];
[componentsForFireDate setMinute: 13];
[componentsForFireDate setSecond: 00];

NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];

// CREO LA NOTIFICA

UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.fireDate = fireDateOfNotification;
notification.timeZone = [NSTimeZone localTimeZone];
notification.alertBody = [NSString stringWithFormat: @"Get inspired. A new quote is available."];
notification.userInfo= [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Some Information"] forKey:@"Quotes"];
notification.repeatInterval= NSDayCalendarUnit;
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

AppDelegate.m 中,我想在用户打开通知且应用程序处于后台时运行一个方法。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

//SE L'APP VIENE LANCIATA TRAMITE LA NOTIFICA
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if (notification)
{
[self.viewController generaCitazione];
}

return YES;
}

我哪里错了?

最佳答案

您使用了错误的 key “UIApplicationLaunchOptionsRemoteNotificationKey”。此键用于推送通知。将以下键用于本地通知。

UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

关于iphone - iOS - 后台本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18642812/

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