gpt4 book ai didi

ios - 提醒不起作用

转载 作者:行者123 更新时间:2023-11-29 00:53:17 29 4
gpt4 key购买 nike

我想根据时间提醒用户,但是使用这段代码无法实现,请给我任何解决方案。这是我的代码:

NSDate *pickerDate = [self.StartDate date];

UIApplication* app = [UIApplication sharedApplication];
UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init];

NSDate *date1=[pickerDate dateByAddingTimeInterval:60];
notifyAlarm.fireDate = date1;
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
//notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
notifyAlarm.repeatInterval =NSCalendarUnitWeekday;
notifyAlarm.soundName =UILocalNotificationDefaultSoundName;
notifyAlarm.alertBody =self.EventText.text;
//notifyAlarm.alertLaunchImage=@"in.png";
[app scheduleLocalNotification:notifyAlarm];
[self dismissViewControllerAnimated:YES completion:nil];

最佳答案

把这段代码写在appdelegate.m中的didFinishLaunch方法中

 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {

[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}

关于ios - 提醒不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37880060/

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