ios - local notifications issue delivering on ipad vs iphone -
i have issues on local notifications app. when test app notifications, on iphone firing once daily on ipad 5x time daily. here's code :
nsdatecomponents *comp = [[nscalendar currentcalendar] components:nscalendarunitday | nscalendarunitmonth | nscalendarunityear | nscalendarunithour | nscalendarunitminute | nscalendarunitsecond fromdate:[nsdate date]]; nsinteger day = [comp day]; nsinteger month = [comp month]; nsinteger year = [comp year]; nsinteger hour = [comp hour]; nsinteger min = [comp minute]; nsinteger sec = [comp second]; nscalendar *calendar = [nscalendar currentcalendar]; nsdatecomponents *components = [[nsdatecomponents alloc] init]; [components setday: day]; [components setmonth: month]; [components setyear: year]; [components sethour: hour]; [components setminute: min]; [components setsecond: sec]; [calendar settimezone: [nstimezone defaulttimezone]]; nsdate *datetofire = [calendar datefromcomponents:components]; // schedule notification uilocalnotification* localnotification = [[uilocalnotification alloc] init]; localnotification.firedate = datetofire; int = arc4random() % 2; if (i == 1) { localnotification.alertbody = @"collect free coins!"; } else { localnotification.alertbody = @"it's time win"; } localnotification.alertaction = @"view"; localnotification.timezone = [nstimezone defaulttimezone]; [localnotification setrepeatinterval: kcfcalendarunitday]; localnotification.applicationiconbadgenumber = [[uiapplication sharedapplication] applicationiconbadgenumber] + 1; [[uiapplication sharedapplication] schedulelocalnotification:localnotification]; nslog(@"local notif = %@", localnotification);
what mistake in code? why seems correctly gives notification on iphone not on ipad?
if in ipad os version > 8.0 have take permission user. write below code in "didfinishlaunchingwithoptions" (appdelegate.m)
if ([uiapplication instancesrespondtoselector:@selector(registerusernotificationsettings:)]){ [application registerusernotificationsettings:[uiusernotificationsettings settingsfortypes:uiusernotificationtypealert|uiusernotificationtypebadge|uiusernotificationtypesound categories:nil]]; }
Comments
Post a Comment