ios - Pop to root view at midnight if app is still running -
i attempting return user first screen of application if app still , running @ midnight , things transition new day.
i using
- (void)applicationsignificanttimechange:(uiapplication *)application
to detect change there issues...
first, there random triggers occurring @ 9:30 or 10:45 causing app kick main screen soon. understand there other factors trigger method daylight savings , messages carrier. neither of applied day triggering early.
so added in code manually check clock hour , minutes checking see if time on device between 11:58 pm , 12:02 am.
//get current time nsdate* = [nsdate date]; nscalendar *gregorian = [[nscalendar alloc] initwithcalendaridentifier:nsgregoriancalendar]; nsdatecomponents *datecomponents = [gregorian components:(nshourcalendarunit | nsminutecalendarunit | nssecondcalendarunit) fromdate:now]; nsinteger hour = [datecomponents hour]; nsinteger minute = [datecomponents minute]; if ((hour>=23 && minute > 58) || (hour == 0 && minute < 2)) { //return main screen }
this worked fine in testing manually adjusting device clock. however, left device on night, woke next morning, , never triggered.
why method finicky? , there better way handle i'm trying do.
you're complaining method being unreliable, , think of (note didn't know existence of method of 10 minutes ago), use completly different way.
from this post understand can schedule actions (through notifications) , would, instead of detect when midnight there, schedule notification @ midnight. method pops root listen specific notification, maybe check it's payload make sure of few things (that's you), , if tests passes, because assume it's been sent @ midnight, can pop.
the thing i'm unsure of advise test if notification sent when app in background/killed.
either way, can check uiapplicationstate before sending notification , react accordingly, current date , time, therefore, when user comes background or re-starts app or anything, know load.
from scratch, without brainstorming, here how understand
user using app => notification sent & read, foreground state => pop root
user has app in background => (unsure notification) => either way, set in nsuserdefaults load root vc, in -
appwillenterbackground
user has app killed, same previous step.
and pretty got situations covered 1 method , 1 notification. have test out make sure haven't ignored important.
Comments
Post a Comment