首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >提醒不起作用

提醒不起作用
EN

Stack Overflow用户
提问于 2016-06-17 11:08:30
回答 1查看 69关注 0票数 0

我想提醒用户基于时间,但不能实现使用这段代码,请给我任何solution.This是我的代码:

代码语言:javascript
运行
复制
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];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-19 11:57:25

在appDelate.m中用didFinishLaunch方法编写这段代码

代码语言:javascript
运行
复制
 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)];
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37880060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档