提醒无效

时间:2016-06-17 11:08:30

标签: ios uilocalnotification reminders

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

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];

1 个答案:

答案 0 :(得分:1)

在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)];
        }