Swift Sprite-Kit - How To Add Notifications [duplicate] - ios

This question already has answers here:
Local Notification on offline (Swift)
(2 answers)
Closed 4 years ago.
Iv'e been working on a topdown shooter game in Sprite-Kit using Swift and Xcode. I was wondering if there was a simple way to make a notification pop up if the user stops playing the app for a certain time (like 2 days for example.)
Also if I decide to add waiting in the future, can I make a notification pop up after and upgrade or something is complete? (this could also help other people viewing this post)
There is probably a similar way of doing these things but I would prefer if there was a simpler was as I am a bit new to Sprite-Kit and I don't want anything to complicated. A function would be nice if possible! :)
Thanks in advance!

If I am understanding you correctly sounds like the problem you are trying to solve has nothing to do with SpriteKit on it's own, but it's more related to triggering of a local or a push notification.
One way to achieve what you are trying to do is to make an object/module that it's sole responsibility is to count the application usage, when user opens the app or however you want to count that. You can trigger local notification that prompts the user that they haven't played the game for the past X days and every time the user uses the app you cancel the old notification and post a new one for the next X days.
Second option would be a server to manage the notifications via push notifications and your app will need to support push notification also tell the server whenever it's used so the server could notify if the app is not used for the past X days.

Related

How to code a diet reminder in iOS?

I'm trying to code an app that reminds me to hit a certain diet goal (drink 8 glasses of water, eat two fruits, take vitamins etc)
The problem is if I code these as reminders using local notifications, I don't get to execute code. So I can't adjust the reminders every hour relative to my goal. For example don't show the reminder if I already hit the goal. Or say stop the reminder past dinner time and start again in the morning.
If I code these as NSTimer the problem is they don't run in the background.
I suppose I can move all the logic to a server and use push notification instead. But this is huge amount of work for what I would consider a very simple self reminder app.
What is the right approach?
if I code these as reminders using local notifications, I don't get to execute code
I use a pill-taking app, and it does use local notifications. The local notification does let the app execute code, if the user taps / swipes (whatever) the notification. The app then puts up a dialog where I enter what actually happened (I took the pill, I skipped it, etc.).
The app simply assumes that if the user doesn't respond and tell it what happened, then nothing happened (i.e. the user missed the pill). How does it know that? Well, as with any local notification-based timer app, the app must maintain an internal list of pending events. It strikes a pending event from the list when it knows the outcome. That way, if the app is not running and then it is running, it can look back over its list and note that there are past pending events, thus proving that the user failed to respond to a reminder.

Trigger iOS app periodically

I'm trying to figure out if there is any permissible way to have my iOS app run periodically (say every 4 hours) and grab a users location. I'm aware of three possible ways this might be accomplished:
Local Notifications (Handling Local and Remote Notifications)
The problem with this solution is that when the app is killed after being in the background a while or the phone restarts, then the local notification will fire and give a UI but not actually start the app so I can't grab the location.
Alarms (Configuring Alarms)
As Apple's documentation says:
Note: An alarm is not intended to serve as a UILocalNotification. An alarm requires you to create an event or reminder that is visible in the user’s Calendar or Reminders app. A UILocalNotification is better suited for general purposes that don’t involve the Calendar database.
Therefore, not only would I be going against Apple's recommendation, but I would then have to ask for access to the user's calendar which won't make any sense to the user.
NSTimer (NSTimer)
I could create a NSTimer, but that solution was already answered here as not viable (That was three and a half years ago but I'm guessing the answer hasn't changed).
Are there any other ways in which this might be accomplished on iOS?
I don't know of any way to grab it periodically every X hours, but the Significant Change Location API might work for your use case. It gives you updates whenever there has been a significant change to the users location.
edit
If you app is not running in the background it will relaunch your app.
/edit
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW10
This stack overflow question has a lot of info about this service also:
Behaviour for significant change location API when terminated/suspended?
See the Getting Location Events in the Background section of Apple's Location and Maps Programming Guide. The other methods mentioned in the question wouldn't actually wake the app up, except for UILocalNotification, and then only when the user tapped in in Notification Center.

Scheduling tasks in iOS - where do i start?

In my app i want to fire a notification after exact time, where i mean days rather than seconds. I need to accomplish that event without using a server side - whole app must be running on the device itself.
So there is my question - is there any class that would let me do that, and will remember tasks even if a user kills the app, or switches his phone off and on?
You are looking for Local notifications.
https://developer.apple.com/library/ios/DOCUMENTATION/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html#//apple_ref/doc/uid/TP40008194

Update ios app every time more data is available on server

I have an app that needs to update every time a java web application creates more data. Simple enough, right?
But I found out that my app can`t run in background to ask for more data periodically, and I think I need to use the push notification system. That seems to be overly complicated for a really small thing.
And then, reading about it, I found out that the push notification can never arrive! For example, if the app is offline when the push notification is sent but is online a few moments later.
So, in that case, how can I update the data? I only bring data from the server when the user logs in. I didn't want to do that every time the application became active...
I guess there is a simple solution but this is my first app, any help would be appreciated.
You see why you should read your question before posting it?
And then, reading about it, I found out that the push notification can
never arrive! For example, if the app is offline.
So, in that case, how can I update the data?
Guess what, if you are offline, there is not much you can do... Moving on to serious things:
iOS7 allows you to do periodic background fetchs (check the Multitasking Enhancements). Have this tutorial.

UILocalNotification design paradigm [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a few questions regarding UILocalNotifications and how I can design my app.
I have an application that monitors an FX (foreign exchange) data feed. What I want to do is add a feature where the user can set an alert to occur when the price hits a certain value.
There are then two scenarios - When the app is running and when it's not.
If the app is running then I can monitor the feed in the app and schedule and display a notification if the price is reached. (this I understand)
If it's not running then am I correct in my asumption that in order to monitor the feed my only option is to use the background task completion in iOS 6?
If so I guess this isn't going to work as I only get 15 minutes on background time, so after that there would be no way to monitor the feed and thus display a notification.
so.... A) is this a correct asumption? B) Is my only way to get longer than 15 minutes background time to use Push Notifications and monitor the feed on a server? C) How will iOS7 change this can I run arbitrary code in the background?
I have read the documenation but I cannot figure out how to present a UILocalnotifcation with a UIAlertView style look, rather than the drop down thing at the top of the screen?
If I schedule more than 64 notifications I understand the OS cancels any after that... Our of interest what if an app (malicious or not) setup 64 local notications (potentially repeating) how could a user cancel these if the app is badly coded and doesn't cancel them itself?? Would a restart destroy any scheduled notifications?
If I want to present a notificaiton when the app is running, do I bascailly catch the notficaiton in a delegate method and arrange to display the message myself?
So here are my ansers:
1A, Yes, the assumption is correct, your app can't run indefinitely in background
1B, Using PushNotifications won't give you longer time to execute in background, but your app can be notified at any time so this can be a a solution, but you can't rely on the notifications order so be careful.
1C I didn't check the latest features of iOS 7 but I doubt that they will provide indefinitely background running (like Android services)
2.Set the alertBody If the value of this property is non-nil, an alert is displayed but I don't think you can force the style of the alert, but if a user has set the style of the alerts then he will expect to receive them with that style so I think you shouldn't bother with this issue to much.
3.Not sure of this one, it's kind of tricky but you can test it ;)
4.YES, use application:didReceiveLocalNotification:

Resources