0

I've got a json file on my server. How do i change its content from an iOS app? I need either write to it or completely replace that file with a new one. Is it even possible? Thanks

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161

3 Answers3

2

This is not specific to iOS and depends on what you understand by "remote file". Typically you'd download JSON contents with a HTTP GET request. In this case the "reverse" operation would be HTTP PUSH. You need the remote end (web service) to support this operation.

proxi
  • 1,243
  • 10
  • 18
1

You can use one of the below methods:

1- Use PHP to edit data in the file by sending a POST request with the changes to your PHP which handles the editing on the server.

2- Use PHP to upload the new file and replace the old one by uploading the file to your specified PHP script (this link can help).

3- Use FTP to transfer the new file & replace the old one (you can use this library or use Apple sample).

MuhammadBassio
  • 1,590
  • 10
  • 13
1

I think you need some kind of API on a server side. Let me explain it by example: You have a route that returns back data in json format (for example list or item reviews). For example

GET domain.com/api/reviews 
(it returns json file)

After that you working with these data and send a request to store it to your server (frequently using the same API route)

PUT domain.com/api/reviews 
(and put new json data inside a request body, fore example in newJsonData = "{....}")

Your script (for example /api/reviews.php) should support 2 kinds of request: GET and PUT. If it's get GET request it returns json data. If it's PUT then it rewrite existing json file with new data.

Read more about REST API:

REST API iOS development

Objective-C: Best way to access REST API on your iphone

Few advices:

  • If you will not have any kind of authenticating on a server side it will be very easy for someone else to store dangerous data on a server using the same request

  • It's very easy to add API support using AFNetworking library: https://github.com/AFNetworking/AFNetworking

Community
  • 1
  • 1
anatoliy_v
  • 1,782
  • 15
  • 24