action at a predetermined time

Discussion in 'iOS Programming' started by yyairr, Dec 20, 2015.

  1. yyairr macrumors newbie

    Joined:
    Dec 20, 2015
    #1
    Hi

    Thank you for taking the time to read my inquiry. Sorry if I am repeating an already debated subject, I am new to this world and can't determine if a previous question is the same as mine.

    I am interested in making an app for iOS that will perform a certain action at a predetermined time (not just a simple alert). This action should prompt regardless of the device being turned off and back on since the action was scheduled.

    I have looked through some methods such as waking the app by an external push notification, but have not found a proper solution yet. (No luck in finding a solution in existing related forum threads, so please tell me if there is a reason why I cannot find it…).

    Please share your knowledge about it, and suggest creative ways to handle this (hopefully existing).

    Thank you!

    Yair
     
  2. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #2
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  4. Mascots macrumors 65816

    Mascots

    Joined:
    Sep 5, 2009
    #4
    You're probably going to have to describe what action you want, the scope of the development (just app, app+server, web app, etc), because there are limits on what you can do when and how.

    Let's say you wanted to perform an action each morning without any server interaction. Unfortunately, apps cannot wake themselves at predetermined times, so you have to do some clever thinking. A solution in this case: when a user was to leave your application, you'd need calculate values for future alert prompts of the week and schedule them out to fire when you'd expect the "action" to take place – not actually perform the action but do enough calculation to get useful values for notifications for the user for the next few days.
    Now, tomorrow the user will get a notification with the predetermined data you calculated today. Then when they open the application tomorrow you can perform the action (in the background or a launch-loading screen, depending on what kind of action). If they open the application a few days later, use a marker from the last date open to determine the days you need to loop that action for and add them in a queue to be processed as they would have been on those previous days.

    But alas, without details I don't know if any of that will be helpful. If you are using a web server to do calculation, you can take advantage of things like Push Notifications, which have limited ability to wake the app; or something like Background Refresh, which allows you to prefetch information (an action that is already processed on the sever and not phone, for example).

    Personally, I strive to prevent awakening of the app until the user commits to it because Apple. Using Push Notifications can become a mess and most phones in the iOS ecosystem are fast enough to calculate information to set predetermined Local Notifications in the ~10 minute background without much effort before iOS kills your app and there are pretty elegant ways of handling queued processing items without impacting user experience on launch. So the former method I described more in detail will always be my suggestion for working with apps that need to schedule actions at specific times.
     
  5. yyairr thread starter macrumors newbie

    Joined:
    Dec 20, 2015
    #5
    Hi

    Thanks for all the tips so far.

    Local Notifications won't work for me, because if I got this right, the user has to click on the notification for the app to take action.

    The action I need it to do in a predetermined time is to open a webpage (on the foreground or background) and preforms some actions in it (as inputting text and press a button). Ideally it will also take a snapshot of that webpage at the end, but that's not critical.

    The app should do that in the appropriate time (not calculate as if it did so in the past when the user opens it. The action must take place in a particular time and date.

    Will any alarm method work? something else?

    Thank you!
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    I don't think such an app is possible, or allowed, in iOS.
     
  7. Mascots macrumors 65816

    Mascots

    Joined:
    Sep 5, 2009
    #7
    Then no, this type of set up cannot be isolated to just an iOS device and will require a remote server to actually perform the task and then deliver the results to the user via Push

    Without explicit user action, you cannot guarantee that an app will wake at any specific point in time regardless of the messages you attempt to wake it with - including push notifications.

    There are a few scenarios that would break this:
    - If a user swipes up and kills your app, push notifications will not trigger a wake up
    - If your user has notifications disabled, then the notification would never be sent and no action would perform
    - iOS decides that your app shouldn't be awakened given the current state, usage, etc.

    The time given to apps to wake is really meant to handle the notification, not necessarily to tell the app to do some other task, unfortunately.
     
  8. yyairr thread starter macrumors newbie

    Joined:
    Dec 20, 2015
    #8
    If the app is running on the background, it is possible?



    Let's say I have to ask the user to open the app sometime during the day (a while before it needs to auto act), will it then work (asuming he wont kill it manualy)? or will it be suspended or something after some time?



    If this is possible to do, but only on some conditions (other then requiring the user to act at the scheduled time), please tell me what are the minimum things that needs to happen in order for it to work on set time automatically. I rather have an app that will tell the user it will work only if 'this and that' then not having it at all.



    Thank you so much!
     
  9. Mascots macrumors 65816

    Mascots

    Joined:
    Sep 5, 2009
    #9
    No, unless the user explicitly opens the app at that time, there is no guarantee of awakening at any point in time using any method. This set up will not work without remote support.

    Background tasks will be suspended ~10 minutes after, with that time not being guaranteed to be chunked together and no real set period of time - it depends on circumstances like memory pressure, user interaction, etc., all of which are out of your control.
     
  10. yyairr thread starter macrumors newbie

    Joined:
    Dec 20, 2015
    #10
    ok

    what kind of "remote support"? not sure what you meant. so with a remote support it can work?

    Thank you!!!
     
  11. Mascots macrumors 65816

    Mascots

    Joined:
    Sep 5, 2009
    #11
    By remote support, I mean an independent server that does the crawling, typing, and clicking and then pushes the results to the users iPhone.

    This action cannot be done in the fashion you want on an iPhone, so it needs to be performed elsewhere, i.e., a remote server handling the requests.
     
  12. AxoNeuron macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #12
    What you are trying to do is most definitely not possible.
     

Share This Page