I'm working on an app right now that lets the user create new records on a recurring basis, and lets the schedule how many days in advance they want to create those records. This will almost always take place at a time when the app is not running, so I'm exploring my options for getting the app to be woken up to create the objects. As far as I see it there are four options, one of which is probably not really an option, since I'm trying to use only CloudKit and avoid creating a server-side component.
Option 1:
Use Background fetch to periodically refresh the records and check to see if anything is changed. In this instance I would probably have some kind of CloudKit record that represented the recurrence, in addition to the record type that needs to be created. Then I can just check the recurrence object and create a new record if needed
Option 2:
Schedule a local notification when the user schedules the recurrence. I thought this was going to work, but as far as I can tell, the app will not actually be launched even if it's a silent notification, unlike remote notifications.
Option 3:
Write some code locally that will check a data structure whenever the app is launched to check to see if any new records need to be created.
Option 4:
Create a server application that will create the records for me. Like I said, not really something that I want to do, even if it's the "best" option usually.
With option 1 you can not be certain that your app is running.
Option 2 won't work. As you said the app won't be activated. Or the notification must nog be silent and the user has to select to open the app.
Option 3 is much better than 1 and 2 if you don't mind that it could happen that the records won't be created for a long time if the user never opens up your app.
Option 4 is the best option for this. you will have full control over when to add what.
But... Do you already know in front what data to add? Then why are you adding that data? Can't you just calculate it and assume it's there? Maybe even based on a settings record or so?
Related
So my App was released to the AppStore some months ago and was free to download. I gained like 2k Users. Now I am implementing an auto renewable Subscription model, so future users can use the demo app for free and subscribe to get the full content.
How ever I want to thank my Users "from day one" by giving them free access to all content without paying the subscription.
Is there a "given way" how to implement this because it seems like a common scenario. If not, does someone with IAP experience has a smart workaround how to handle/implement it?
Thanks guys :D
The answer from Paul didnt work for me. Neither did any other solutions.
But i managed to find a solution.
In case you use CoreData as database within your app, you can use the solution i found out for my app.
The idea:
If someone downloads the app from the appstore, he will receive the latest database version in your app.
If someone updates your app, coredata will perform a migration. And this migration updates from bottom to top trough your database versions.
Through this behavior we have the opportunity to dinstinct the two cases.
Solution: We create two new database versions. One will only be updated by the former users. We will set a flag here. The new Users will never get in touch with that.
The first new one will create a new attribut field in any entity (e.g. User) e.g. isFormerUser as a Bool. You can set it per default on true.
Now we create a second new one (the latest one). Trough a Core Data mapper it will take the $source attributes if it migrates.
So by that case, all FormerUser were set on True and will keep that attribute.
Here will the default be False, so if $source didnt exist, set it on false (new Users).
This solution is nice because it gets set once by that migration/update and you dont have to carry hardcoded stuff in your app. Now just create a load/get Function from CoreData for that attribute and set a variable to use in an if-statement.
I am mainly just looking for clarification or resources. Let me explain my situation.
I have an app that internally relies on an always-up-to-date database of items. I'd like to show off items that were released close to today's date. I originally thought I'd just query my database and fetch the relevant items from there. So I began the long process of updating target values so the widget could see my classes, etc... But that was such a HEADACHE.
I thought surely there must be a more lightweight method the designers had in mind, so I then read about "app groups" and being able to pass information via saved settings/preferences. So basically when the app runs, you store some data as json and then you can fetch that information in your widget.
But then, to my knowledge, the data won't update unless the user runs the app again. I was hoping I could keep this widget up to date even if the user hasn't used the app in a long time.
What exactly is the process I should be using to achieve this? Are "app groups" basically the only way to do this? Will I just have to accept that I will often times have stale data?
The CloudKit WWDC videos recommend implementing sync like this:
Track local changes
Send changes to the server
Resolve conflicts
Fetch server changes with CKFetchRecordChangesOperation
Apply server changes
Save server change token
I'm following this pattern in my app, but I'm running into a problem with deletion and parent-child relationships.
Let's say we have a list of books that are split up into categories. Every book has to belong to exactly one category.
I start with data like this:
SERVER
Thrillers: "Look Out!", "Secret Spy"
Non-Fiction: "Sailing the Seas", "Gardening Adventures"
Computer Programming: <empty>
As you can see, the final category is empty. Let's say I have two devices with exact copies of this data.
Now, on Device 1, the user adds a book CloudKit Sync to "Computer Programming":
DEVICE 1
Thrillers: "Look Out!", "Secret Spy"
Non-Fiction: "Sailing the Seas", "Gardening Adventures"
Computer Programming: "CloudKit Sync"
But on Device 2, the user completely deletes the "Computer Programming" category (it's empty, so this is fine from Device 2's point-of-view):
DEVICE 2
Thrillers: "Look Out!", "Secret Spy"
Non-Fiction: "Sailing the Seas", "Gardening Adventures"
Device 1 syncs first, so it creates a new Book entry with its parent field set to Computer Programming.
But now Device 2 starts its sync process. It applies its changes to the server, so it deletes the CKRecord corresponding to "Computer Programming". This is consistent with Device 2's worldview, where the category is empty and can be deleted.
However, when it deletes this category from the server, this doesn't make sense with respect to the worldview of Device 1 and the server itself. There's now an orphan book called CloudKit Sync that has a dangling pointer to its parent.
If I'm following Apple's recommendations from WWDC, how do I avoid this scenario? Depending on the order of the sync, I can easily arrive at an inconsistent state with an orphaned book and an invalid parent reference.
What I'd like to happen is for the Delete command from Device 2 to return an error telling me I'm going to orphan a book and prevent the action from occurring at all, so I can take some action to fix the situation.
Is that possible? Is there another way to approach this?
Yes, the behavior you want for Device 2 is possible. I see three aspects of cloudkit that will come into play in your scenario. Let's look at those first, then how they might be used in your scenario.
First, assuming that both (or all) devices have subscribed to changes to the appropriate records, each device would be notified that someone else added or removed something. The device receiving the alert would then have the opportunity to decide what to do about it. (remove it from it's local view, replace it on the server, etc)
Second, you can set the behavior for handling conflicts using the savePolicy on the CKModifyRecordOperation. You can specify whether the last change should overwrite older records, throw an error, etc. See https://developer.apple.com/documentation/cloudkit/ckrecordsavepolicy?language=objc for the three options. (I've only used this in the context of two users modifying a common record, but a deletion after another user updated the record should then throw a server record changed error).
Third, assuming you've configured the aforementioned savePolicy, is the server change token itself. I find it easiest to envision the change token as just a last-modified timestamp. "My copy of this record was last modified at 10:42pm" kind of thing. Depending on the overwrite options you've selected in the aforementioned savePolicy, the device will receive an NSError Server Record Changed alerting you that the version on the server is from, say, 10:56pm, and that your local version may no longer be valid.
The userInfo in the resulting NSError includes 3 versions of the record in question: the current version on the server, the version you tried to submit, and the common ancestor version. The guides from Apple say it's up to the developer to decide what how to merge this information. But in theory, you'd be able to diff the changes, decide which you want to keep, and then submit a new operation.
Regarding your specific scenario: Assuming you fully authorize and trust both dev1 and dev2 to delete records, then I would subscribe to creation and deletion events, and set the savePolicy to throw an error when attempting a conflicting change. In this case, Device 1 would add the record and Device 2 would receive the notification of the new record. If Device 2 simply attempts to delete the old record, it should fail with a server record changed error, which you could display to the user as
"Someone else modified this record, do you really want to delete it
(y/n)."
Device 2 would have to refresh the record (and receive the new record change token) before proceeding. After that, if Device 2 still wants to delete the new record, it could, but then Device 1 would be notified of the change via the aforementioned subscription. Device 1 would then download the new record to (or in this case remove the old record from) its local view. The subscription notification could alert user 1:
"Your record Foo was just deleted by Bar"
This will work even if the events happen practically simultaneously, because one of the changes will be applied on the server first and the other device's token will immediately become out-of-date. So, if Device 2 managed to delete the record first, Device 1's attempt to modify the record will fail with server record changed because Device 1's change token is now out of date. Device 1's error handler would have to decide whether to honor the deletion or to proceed with creating a new record based on your business rules. Maybe ask user 1 with something like:
"Computer Programming" has been removed from the server. Do you want to recreate
it?
At this point, user1 can send flame emails demanding other users stop deleting their newly created records, and user2 can demand that people stop recreating the records they just "cleaned up." :)
You could get a lot more complicated, maybe giving device 1 precedence over device 2, such that when device 1 is notified that the record is deleted, then device 1 re-writes the record to the server. If you have multiple users with deletion rights, you could determine an order of precedence and build out the appropriate error/notification handlers. However, this seems excruciating complicated and error prone. Loops that auto respond (create, delete, create, delete, create, delete) could occur. I include it only as a hypothetical example, not a recommendation!
Lastly, as a different example, my app has a different scenario. The records in my case are gaming sessions. All players need read access to the session data, but only the originator is given the option to delete the record altogether. So, you might consider whether you really authorize multiple users to delete shared records or not.
I was wondering if it would be possible to programmatically make users agree to the Terms of Service I have for my application, but for them only to have to agree to it the first time they run the app straight after downloading it, as Apple requires Terms and Conditions for a social networking type application. Any help would be much appreciated as it will be one of the deciding factors on whether my app makes it to the app store or not.
Here a simple solution:
Put your to-be-called method in your delegate's application:didFinishLaunchingWithOptions, which means the T&C are shown to the user as soon as he starts the application. Then for the "once-in-a-lifetime" you could simple store a value in NSUserDefault(e.g. a string "alreadySent") at the end your custom method, which will persist over time as soon as the user doesn't delete application & data.
So the flow of event could be
App launch
Check: is the NSUserDefault value "alreadySent"?
No: Ok call method and show T&C
Yes: skip
This is a simple method which gives you a one-shot way to show the user what you want.
(Just google if you don't know how the NSUserDefault works, it's straightforward)
I am developing a gallery which allows users to post photos, comments, vote and do many other tasks.
Now I think that it is correct to allow users to unsubscribe and remove all their data if they want to. However it is difficult to allow such a thing because you run the risk to break your application (e.g. what should I do when a comment has many replies? what should I do with pages that have many revisions by different users?).
Photos can be easily removed, but for other data (i.e. comments, revisions...) I thought that there are three possibilities:
assign it to the admin
assign it to a user called "removed-user"
mantain the current associations (i.e. the user ID) and only rename user's data (e.g. assign a new username such as "removed-user-24" and a non-existent e-mail such as "noreply-removed-user-24#mysite.com"
What are the best practices to follow when we allow users to remove their accounts? How do you implement them (particularly in Rails)?
I've typically solved this type of problem by having an active flag on user, and simply setting active to false when the user is deleted. That way I maintain referential integrity throughout the system even if a user is "deleted". In the business layer I always validate a user is active before allowing them to perform operations. I also filter inactive users when retrieving data.
The usual thing to do is instead of deleting them from a database, add a boolean flag field and have it be true for valid users and false for invalid users. You will have to add code to filter on the flag. You should also remove all relevant data from the user that you can. The primary purpose of this flag is to keep the links intact. It is a variant of the renaming the user's data, but the flag will be easier to check.
Ideally in a system you would not want to "hard delete" data. The best way I know of and that we have implemented in past is "soft delete". Maintain a status column in all your data tables which ideally refers to the fact whether the row is active or not. Any row when created is "Active" by default; however as entries are deleted; they are made inactive.
All select queries which display data on screen filter results for only "active records". This way you get following advantages:
1. Data Recovery is possible.
2. You can have a scheduled task on database level, which can take care of hard deletes of once in a way; if really needed. (Like a SQL procedure or something)
3. You can have an admin screen to be able to decide which accounts, entries etc you'd really want to mark for deletion
4. A temperory disabling of account can also be implemented with same solution.
In prod environments where I have worked on, a hard delete is a strict No-No. Infact audits are maintained for deletes also. But if application is really small; it'd be upto user.
I would still suggest a "virtual delete" or a "soft delete" with periodic cleanup on db level; which will be faster efficient and optimized way of cleaning up.
I generally don't like to delete anything and instead opt to mark records as deleted/unpublished using states (with AASM i.e. acts as state machine).
I prefer states and events to just using flags as you can use events to update attributes and send emails etc. in one foul swoop. Then check states to decide what to do later on.
HTH.
I would recommend putting in a delete date field that contains the date/time the user unsubscribed - not only to the user record, but to all information related to that user. The app should check the field prior to displaying anything. You can then run a hard delete for all records 30 days (your choice of time) after the delete date. This will allow the information not to be shown (you will probably need to update the app in a few places), time to allow the user to re-subscribe (accidental or rethinking) and a scheduled process to delete old data. I would remove ALL information about the member and any related comments about the member or their prior published data (photos, etc.)
I am sure it changing lot since update with Data Protection and GDPR, etc.
the reason I found this page as I was looking for advice because of new Apply policy on account deletion requirements extended https://developer.apple.com/news/?id=i71db0mv
We are using Ruby on Rails right now. Your answers seem a little outdated? or not or still useful right now
I was thinking something like that
create a new table “old_user_table” with old user_id , First name, Second name, email, and booking slug.
It will allow keep all users who did previous booking. And deleted their user ID in the app. We need to keep all records for booking for audit purpose in the last 5 years in the app.
the user setup with this app, the user but never booking, then the user will not transfer to “old_user_table” cos the user never booking.
Does it make sense? something like that?