ios - Check if Local Notifications allowed -


i'm repeating local notification @ same time every day.

right working fine, except when notifications toggled off, on, there build of notifications days off.

is there best way check if toggled off on, , clear old notifications?

thanks!

- (void)viewdidload {     [super viewdidload];      uiusernotificationtype types = uiusernotificationtypebadge | uiusernotificationtypesound | uiusernotificationtypealert;     uiusernotificationsettings *mysettings = [uiusernotificationsettings settingsfortypes:types categories:nil];     [[uiapplication sharedapplication] registerusernotificationsettings:mysettings];      // before create new ones, cancel existing notifications     [[uiapplication sharedapplication]cancelalllocalnotifications];      uilocalnotification* localnotification = [[uilocalnotification alloc] init];      nscalendar *cal = [nscalendar currentcalendar];     nsdatecomponents *comp = [cal components:(nscalendarunityear | nscalendarunitmonth | nscalendarunitday | nscalendarunithour | nscalendarunitminute) fromdate:[nsdate date]];     comp.hour = 19; // 19 = 7pm     comp.minute = 45; // 7:45 pm     comp.second = 01; // 7:45:01 pm      localnotification.firedate = [cal datefromcomponents:comp];     localnotification.alertbody = @"local notification in ios8";     localnotification.timezone = [nstimezone defaulttimezone];     localnotification.repeatinterval = nscalendarunitday;      // schedule notification fire @ fire date     [[uiapplication sharedapplication] schedulelocalnotification:localnotification];     // fire notification right away, still fire @ date set     [[uiapplication sharedapplication] presentlocalnotificationnow:localnotification]; } 

before presenting notification check if users settings allow it:

- (void)viewdidload {     [super viewdidload];      uiusernotificationtype types = uiusernotificationtypebadge | uiusernotificationtypesound | uiusernotificationtypealert;     uiusernotificationsettings *mysettings = [uiusernotificationsettings settingsfortypes:types categories:nil];     [[uiapplication sharedapplication] registerusernotificationsettings:mysettings];      // before create new ones, cancel existing notifications     [[uiapplication sharedapplication]cancelalllocalnotifications];      if ([[[uiapplication sharedapplication] currentusernotificationsettings] types] != uiusernotificationtypenone) {          uilocalnotification* localnotification = [[uilocalnotification alloc] init];          nscalendar *cal = [nscalendar currentcalendar];         nsdatecomponents *comp = [cal components:(nscalendarunityear | nscalendarunitmonth | nscalendarunitday | nscalendarunithour | nscalendarunitminute) fromdate:[nsdate date]];         comp.hour = 19; // 19 = 7pm         comp.minute = 45; // 7:45 pm         comp.second = 01; // 7:45:01 pm          localnotification.firedate = [cal datefromcomponents:comp];         localnotification.alertbody = @"local notification in ios8";         localnotification.timezone = [nstimezone defaulttimezone];         localnotification.repeatinterval = nscalendarunitday;          // schedule notification fire @ fire date         [[uiapplication sharedapplication] schedulelocalnotification:localnotification];         // fire notification right away, still fire @ date set         [[uiapplication sharedapplication] presentlocalnotificationnow:localnotification];      } } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -