so I'm using OCPrayerTimes to get a set of strings in an
I use this code to get the array,
NSMutableArray *prayerTimes = [prayerTime prayerTimesDate:[NSDate date]
latitude:3.1667
longitude:101.7000
andTimezone:[prayerTime getTimeZone]];
I then set notifications for each date in that array. Now my problem is that everyday those dates change so the user would have to re-open the app at midnight to get the new dates so the notifications would work.
Would I have to somehow run the viewdidload method at midnight everyday?
Thanks.
You can't automatically run your app every day, but you can schedule up to 64 local notifications, so you could calculate the prayer times for the next 12 days, and schedule notifications for all of them. This way the app wouldn't have to be opened every day.
Related
I'm trying to implement local notifications to my app. They will function as a reminder for an event, but the notifications must come from my app, and not from Calendar or Reminders.
My question is, how can I create notificaitons that fire before a certain date, while showing the actual date in the 'time-field'?
This is what the Calendar can do:
Notice the top right corner saying "in 5m".
I'm trying to get the same functionality for my own notifications, but I can't find anything about it. This is the only thing I can get:
As soon as the notification arrives, it says "Now", and then proceeds to count up the amount of minutes ago. I need it to be sent X minutes before, and count down to "Now", then count up. Is this possible?
How about you create multiple custom Notification.Name like this posting. You could have .onTime, .fiveMinutesReminder, .tenMinutesReminder, and so on. The logic in your app would set when to fire those reminders. Your selector handler function would need to have some kind of switch statement to handler different reminder. The handler will need to show different text message based on the kind of the reminder.
I'm currently making a TODO app and I save the date that the user has to do a thing. Let's say that he saves the date 28-7-2016 to do something, I make another column tobenotified and I take the date minus it by 1 and save it, so the user should be notified the previous day that tomorrow has a thing to do.
But what if the user has closed the app(killed it). What is the proper way to send a notification from the Realm database when the date tobenotified is equal with NSDate() / the current date?
It's not as simple like that. Realm queries can neither match against a live-updating current date nor send notifications from the background.
You want to look into UILocalNotification and set it up with the tobenotified date as fireDate and schedule it locally. Note that you will require your users consent and have asked them initially by registering for local notification types so that you're permitted by the OS to schedule and present notifications. Also if the user can modify or delete a reminder, then you need to find a way to identify the notification via the the provided identifier and remove or re-schedule it accordingly.
I am creating an iOS app in Objective C. I don't want to pay for a server, but I want to create a reward system so that every 3 hours the user is rewarded with "coins" when they enter the app. For example, if a user exits the app at 1pm and re-enters the app at 5pm, a reward will be ready. However I want this to carry over even if the app is not running in the background.
Is this possible?
Maybe not a timer here, but save users' exit time through NSUserDefaults, and then whenever users re-enter the app, compare the exit time with the current time to see if the gap is 3 hours.
For example, in viewWillDisappear()
You might save the exit time through:
NSUserDefaults.standardUserDefaults().setObject(NSDate(), forKey: "exitTime")
And in viewDidLoad(), you could extract the exit time through
NSUserDefaults.standardUserDefaults().objectForKey("exitTime")
In your AppDelegate , you can save exit date time to NSUserDefaults
when below function did called
func applicationWillTerminate(application: UIApplication)
func applicationDidEnterBackground(application: UIApplication)
when user enter foreground, you can compare exit time with current time and give some coins
but this way have some problem
if user edited iPhone's date or time in setting , can get a log of coins
but if you use server , you can compare date correctly
there are some idea to solve this problem without server
how about save current time or date periodically ?
this is usecase
user edit iphone's time to 3 hour after
user enter app
user get coins
user edit iphone's time to 3 hour before
user lose coins and some item
if currentdate is earlier then saved currentdate then you have to take coins because that is invalid coins
how about my idea?
I'm seeing really weird behaviour in my iOS app using the ABAddressBook library. Wondering if anyone can give me some insight into whats happening in the background or if I have a logic error I just can't see.
Long story short I'm making a VOIP app that relies heavily on importing the user's contacts. I keep an online backup of these that are also used in conjunction with push notifications.
As they are modified on the phone I need to send an update request to the server to keep them accurate. The problem is many user devices are frequently spamming the server with very large blocks of contacts, at random intervals. One day it will be 50+ contacts, 5 mins later another 10, then it will be a month before a single one is updated. I have asked a few users that are friends and they can't recall modifying half of their address book over night.
My code is very simple, I store an NSDate every time I am required to send an update to the server, e.g. addition, modification or deletion. I know there is a callback that triggers when the address book has been updated, but this requires keeping a reference to the address book in memory at all times. I've done some testing and if the app crashes or the user kills the app, I loose any updates. Given its a background running VOIP app I feel it is possible people will kill it on an occasion to save battery or whatever. So for that reason I loop through all the contacts checking the kABPersonModificationDateProperty property against the last NSDate I have recorded. If the modified is newer I begin my update, like so.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSDate *lastChecked = [dateFormatter dateFromString:[PListData readStringFromFile:#"lastContactsArchive"]];
CFDateRef modifyDate = ABRecordCopyValue(ref, kABPersonModificationDateProperty);
...
...
else if ([(__bridge NSDate*)modifyDate compare:lastChecked]==NSOrderedDescending) // if modified after last check, create new contact and update
{
...
}
Is there something that I'm missing, is the modification date only updated when the name / phone numbers / email etc are changed ? Are they modified when iCloud syncs for example ? is a counter updated if they call the person on the phone ? etc.
I've tried debugging on 3 phones and all behave as I would expect. I'm really drawing a blank here and the server isn't happy with me so any help would be appreciated.
Contacts may also update in background when iphone syncs contacts with iCloud / CardDav / Gmail / Exchange account.
Note that it also may happen while your app is running, so you should subscribe for address book updates.
This question already has answers here:
NSDate: Get precise time independent of device clock? [duplicate]
(4 answers)
Closed 9 years ago.
Currently i am developing one gaming iOS application which i will give to some of my customer for demo.
But while distribution of my app i want to set an expiry mechanism in my app, so that it will get expire after "N" number of days.
It means that (e.g. after 30 days) my app won't work.i can able to this by using system date & time, it means whenever my program starts i check today date and expire date.
The problem is if the user changes system time, my comparison won't be correct.
Also if user delete & reinstall the app,it wont work.
Any help or suggestion?
Look at Ad Hoc Distribution
Ad-hoc development builds last for 3 months, however if you want to add a time limit then you could:
Add a key-value in NSUserDefaults which stores the start date of the app (time taken from a webservice such as http://www.earthtools.org/webservices.htm#timezone) then every time the app enters the foreground check the time against it and if it is over the threshold then to cancel loading the app.
NSDate *now = //load current datetime from restkit
NSDate *startDate = [[NSUserDefaults standardUserDefaults] objectForKey:#"startDate"];
NSDate *futureDate = [NSDate dateWithTimeInterval:60 * 60 * 24 * 30 sinceDate:startDate];
if ([futureDate compare:now] == NSOrderedAscending) {
//stop the application loading by loading a NIB and displaying a message.
}
I would recommend using RestKit to request data from the web-service.
When the app expires, store something in the Keychain to indicate this fact. Then just check that at startup, rather than the date.
Alternatively, you can have it check a web service you control.