I am developing an application which have some pre loaded app resources that can be changed dynamically by user or admin, I have to put these app resources in document directory of my app so that it will not make me to update application on itunes.
Problem that I am facing that i have to download all the app resources from web server on local device when application launches for the first time.
I am seeking for the best method for fetching all my app resources and keep it updated? Please help me!
Actually, The problem is that I have thousands of resources like images, html and css files that have to be downloaded, and end user might feel problem in refreshing or maintain the data on server. Is there any file transfer protocol (ftp) library in iOS available to download the data and update? or any other method?
1) First time, take all the records from server along with the server date(check date parameter, if null then server passes all records i.e. first time app is launched).
2) Store that date in NSUserDefaults.
3) Second time pass that date while request, if date is not null(request is not first time).
4) Server checks the updated records(records greater than the date which you passed).
NSString *strTodaysDate = #"";
if ([[NSUserDefaults standardUserDefaults] valueForKey:#"SyncDone"] != nil)
{
//If sync all data is done first time, then pass server date else pass empty date parameter.
strTodaysDate = [NSString stringWithFormat:#"%#",[[NSUserDefaults standardUserDefaults] valueForKey:#"SyncDate"]];
} //call web service with strTodaysDate as a parameter.
You need to send simple request from application everytime application launches, which will ask server about updates.
If your content on server was updated then you need to reload your content in application.
Of course your server must know if there was some changes in content. You can track changes time on server and latest content update time in application.
You can update data of your by calling web service from application delegate from this method
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
//make call to web service and save it in your document directory
}
Related
I need to keep track of devices that are actively running the app. Right now I have a status field that changes to 1 when the app is first launched or when the device becomes active. When the user presses the home button, I set the status field to 0 upon receiving the notification UIApplicationWillResignActiveNotification
if(self.device) {
[self.realm transactionWithBlock:^{
self.device.status = 0;
}];
}
self.device = nil;
[self.realm refresh];
However, I check the data in Realm Cloud, and it doesn't seem to be updating at all. Is there some way to force update the sync of my Realm data?
If you want to achieve this by only using realm platform, I think you should implement a data updating logic, for example, every 5-second client should update a value, it can be the current timestamp and you can recognize online users by the last timestamp value.
in my opinion, a simple socket.io implementation can be a better solution, you can save users connection status by saving them in the socket server. you just need to save timestamp when the client has connected to the server and when he has disconnected.
I believe you can do same with ROS but I'm not sure they provide public API for user connection event or status ...
I'm trying to use Firebase for a partially offline app, it seems to have all the offline capabilities I need but I'm having issues with fetching data while offline. The JSON structure I want to store is a single reference to a user profile:
{
"Profiles" : {
"pOnv3q1PxqPyqKH0uqtDYaXqvqF2" : {
"firstName" : "John",
"lastName" : "Doe"
}
}
}
I've set Database.database().isPersistenceEnabled = true and keepSynced(true) set for the reference I want to keep cached offline. I set keepSynced(true) both when I create the reference the first time and when I load it on subsequent launches.
Scenario 1 - Works
If I launch the app online, the reference is created and saved to the online database. If I close the app with it still online and fully kill it, then relaunch, the reference is found as you'd expect.
Scenario 2 - Works
I launch the app offline, create the reference offline and save it to the cache. I fully kill the app and relaunch it and then reconnect, the reference is pushed to the online database from the cache as you'd expect.
Scenario 3 - Does not work
I launch the app online, create the reference and exit while still online. I kill the app and then relaunch it offline, only to find that the reference had not been stored in the cache and isn't being loaded.
These scenarios seem to me like the requests to the online database are being successfully cached, but the database itself is not.
Am I misunderstanding the Firebase offline functionality or should this be working? It's worth noting that this is in Xcode9, iOS11 and Swift 4 so there may be compatibility issues.
The code I'm using to fetch this reference is:
Database.database().child("Profiles").child(userId).observeSingleEvent(of: .value) { snapshot in
print(snapshot)
}
On failed fetches this is returning an empty snapshot. I was under the impression that if the local cache had no idea of the presence of a key then the completion handler wouldn't be called, however it is being called leading me to think that the key exists but the data isn't being fetched properly.
Ideally the user would be able to sign up offline and have basic functionality, then push the data when a connection is established, but currently the profile can only be loaded with a connection available.
Any help would really be appreciated.
My iOS App call a API with Restful webservice API. Then I used data and saved Json data on my disk.
On next time open app, I want to check API, if having update, the app will call and be reveice data, if not update I will use data on disk.
How to check API update? Thankyou.
If you have influence on the API then you can make a call that returns for example a timestamp of latest update. If it is newer than the one you have on your device then download the new data. Because you probably want to avoid downloading the (same) data twice. Is that what you were asking?
You can use this method in AppDelegate, which will be called when app come back to foreground. Call the API and check it's last modification date of you'r data.
func applicationWillEnterForeground(application: UIApplication) {
}
I want to create a PFObject and have it saved locally so that if the user quits the app (or heaven forbid, it crashes) the object is still intact on the device BUT not uploaded to the server until the user is ready to submit it. Is this possible?
I know there is the 'saveEventually' method, but my understanding of that is it will at some point save itself to the server automatically, which is not what I want. I want to save locally only and only upload to the server when the user is completed finished.
If you have enabled the local datastore, calling pinObjectInBackground() on an object should make the object persist between sessions. Every time you make changes to the object that you want to save, call pinObjectInBackground() again. The object will not be saved to the server until you call saveEventually() or some other save function. Any query using fromLocalDatastore() will be able to fetch your locally stored object as long as it is pinned.
I am writing an iOS app with a Rails API backend. The Rails backend will serve JSON data to the app. I have the following requirements.
The app will be a free download
The app will show data on a map
The app will show data in the vicinity of the user
Upon loading the app the device should send some unique identifier to the server identifying itself as a device that is running this app.
There will be no authentication for the user as it is not required. The data is available to anyone who downloads the app. All the server needs to know is that the client is a device running the app. The server cannot serve data to any other client
I would like to run the data using SSL between the device and server
The user location will be sent to the server and the server returns the corresponding pieces of data that are in the vicinity of the user
The client receives the JSON and caches the data locally.
Question: Given these requirements, how to set up steps 4 & 5?
Also: If I want to search more on this topic what keywords should I be googling for?
Consider using OpenUDID or SecureUDID.
I give you 2 options.
First of all, the easy way. From some time, apple forbids access to the device ID. However, they give you a device token instead.
To get this unique token, the user must register for remote notification.
Upon application launching, call the following function:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Then this callback will be called:
- (void)application:didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken.
Send the token to your server and you're done. Problems with this approach are obvious. Your user will have to register for remote notification.
Another approach is to use the MAC address of the wi-fi board.
To do this:
IPAddress.h
IPAddress.c
Import this files into your project.
Then use this function:
InitAddresses();
GetHWAddresses();
for (int i=0; i<MAXADDRS; ++i)
{
//There is a way you can obtain more info about the hw_addrs, but in general, it's the first.
NSLog(#"MAC: %s", hw_addrs[i]);
}
FreeAddresses();
Create a hash using the mac address above and you're done.
Hope it helps.
Upon first launch, the app sends a request to the server saying Hi, I'm a new client, give me an id! The server generates a new, random id and sends it back. The app saves the id locally and uses it henceforth to uniquely identify itself.