How to implement registration of iOS applications on a remote server with a backup in an offline log?

I want to log iOS application events on a remote server.

When the server is accessible from the device, I call the API call to the server. When the device is disconnected, I add the log to a text file.

In each run, I plan to check server availability, and if it is reached, the background thread starts, which rotates the log file, downloads the old log file using the POST request to the server, and deletes the old log file from the device. It's good?

However, if there are long intervals between connection availability, then theoretically the offline log file can become really large and difficult to download.

What are the alternatives to ensure that the logs (both from online and offline) end up reaching the remote server?

+6
source share
5 answers

You can see Bugfender , this is a product that we created to solve this problem.

It is easy to integrate, and you can choose which devices you want to receive logs from. Our service works offline and online, we spent a lot of time to make it reliable and easy to use.

+2
source

I just built my own solution: https://github.com/kennethjiang/Teleport-NSLog . Take a look at the "SimpleHTTPForwarder" function you need.

But the long story is short, I do not even check for availability. The freight forwarder wakes up periodically and simply blindly tries to send the magazine to the backend. If this succeeds, it deletes the local log file. Otherwise, if for some reason it does not work, for example, the connection timeout, it simply skips this move and waits for the next one.

Since the sender always runs in a sequential queue, there is no problem with concurrency / race condition. The code is simple and clean!

+1
source

You asked, "This is good, what needs to be done"? The answer depends a lot on what your application is and how you intend to use the data, so I'm not sure if anyone can answer this for you ... Removing old logs on the device? Sounds like a great idea if they are as big as you suggest later. However, I would advise you to consider the privacy of your users. Will they be notified of the data you collect about them? Will you provide an opportunity to refuse?

Is there an alternative for your scenario? No. If you plan to send data to the server in the end, and you do not have an Internet connection, you need to store it somewhere locally. How could there be another option? No, there is no other choice. Big magazines take up a lot of memory.

0
source

Take a look at NSLogger . This may be helpful.

0
source

As for saving offline logs in files on a daily basis, every day gets its own file. Thus, you can send it to pieces and get rid of the need to read the contents of the massive log file in memory when you finally have a connection and will be sent to the server.

0
source

Source: https://habr.com/ru/post/955604/


All Articles