mardi 5 juillet 2016

Objective-C: Annoying - I get about 5-6 Notifications per minute from my UILocalNotifications


How to fix this issue? This is my code:

NSDate *dateToSet = [NSDate dateWithTimeIntervalSinceNow:1.0];
NSString *message = @"Test notification";
UILocalNotification *warningNotification = [[UILocalNotification alloc] init];
warningNotification.fireDate = dateToSet;
warningNotification.timeZone = [NSTimeZone defaultTimeZone];
warningNotification.alertBody = message;
warningNotification.hasAction = NO;
warningNotification.userInfo = nil;
warningNotification.repeatInterval = NSCalendarUnitDay;
warningNotification.soundName = nil;
[[UIApplication sharedApplication] scheduleLocalNotification:warningNotification];

And my AppDelegate.m (didFinishLaunchingWithOptions):

UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}

[[UIApplication sharedApplication] scheduledLocalNotifications];
[application registerForRemoteNotifications];

enter image description here


Aucun commentaire:

Enregistrer un commentaire