Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Best way to upload/download level files (iOS)
Started by thomas6 Feb 21 2019 04:29 AM

- - - - -
9 replies to this topic
upload download level data files ftp ios
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 936 posts
  • Corona SDK

Hola!

 

I'm struggling with upload and download of my level files on iOS, so I'm wondering how you all do it, and if you have any surefire methods to do this. I have done my research, and "had" working code, but all of a sudden for some reasons that code is not working anymore...

 

I was using Graham Ranson's ftp.lua helper code, which works really well on the simulator, and used to work on my iPad, but the exact same code now gives me a "host or service not provided, or not known" error. I'm assuming that an iOS update my downloading data from remote servers safer and also more demanding (read: app transport security stuff, most likely).

 

I checked out the network.upload() documentation. That's an option, but it looks like I will need a companion PHP script running on my server to make sure the files are stored in a specific location. Does anyone have such a script, and willing to share?

 

Regarding the ftp.lua code - does anyone have any success running this on a current iOS device? Any insights on which types of security might be required by iOS but not by MacOS? (as the code does run on the simulator on my macbook pro, but not on my iPad). Or insights about which lines of code I could try in my build.settings to make sure my iPad allows this FTP traffic?

 

Any help and info is much appreciated, as this issue is halting my development at the moment (on a 7-year project!!)

 

Thanks,

Thomas



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 611 posts
  • Corona SDK

There isn't really one best method. It really depends on the kind of data that you are working with, how you want users to access the levels, etc.

So far, I've always worked with a PHP & MySQL setup. In the projects that I've worked on, the levels have always been put into JSON format, then a HTTPS request is sent to a PHP file on a server, which then handles the downloading or uploading of a level (and other logic) and returns the expected result back to the app.

I've never had any issues this way.



[TOPIC: post.html]
#3

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 936 posts
  • Corona SDK

Hi Xedur, and thanks for your response!

 

You are very right, there isn't one best way, and my post subject is misleading: I'm not really looking for the single best way, I'm just looking for a way that works, since my way of working seems to have broken with a recent iOS update.

 

I also have my levels in a JSON format. Your idea of using a PHP & my SQL is a good tip, that might work for me, so I'll give that a go if I don't manage to fix my existing FTP setup. I would prefer using plain FTP over mySQL, because that gives me easier access to my level files (I literally have my FTP window open in my text editor for instant access), but I can find workarounds for that.

 

So, thanks for the tip! All other tips also still welcome! ;-)



[TOPIC: post.html]
#4

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,036 posts
  • Corona SDK

I use Gamesparks. It is fairly simple to save and download not only json files but also entire lua files.by app and/or by users. For better or for worse Gamesparks is not essentially free anymore so I might have to look at other options if I ever create a new game. Other options include @develoophant products, PlayFab (they charge .10 cents per gig download) or what Xedur mentioned.



[TOPIC: post.html]
#5

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 936 posts
  • Corona SDK

Hi Agramonte. Thanks for the tips. Paying for an extra service will be my last recourse, since I have a paid for hosting package including FTP, PHP and mySQL so I should be able to use this, preferably.



[TOPIC: post.html]
#6

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 936 posts
  • Corona SDK

Also, more research about the error message that I get on my iOS device ("host or service not provided, or unknown") seems to point at the difference between IPv4 and IPv6. Possible the simulator uses IPv4 and the iOS device IPv6, or the other way around. This might explain the difference in behaviour. But it still doesn't fix my issue though :-)

 

Best regards,

Thomas



[TOPIC: post.html]
#7

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 611 posts
  • Corona SDK

Yeah, iOS has supported IPv6 addresses only for quite some time.

"Starting June 1, 2016, all apps submitted to the App Store must support IPv6-only networking. A majority of apps will not require any changes as IPv6 is already supported by NSURLSession and CFNetwork APIs. However, if your app utilizes IPv4-specific APIs or hard-coded IP addresses, you will need to make changes. Be sure to test for IPv6 compatibility before submitting your app to the App Store for review."
https://developer.apple.com/support/ipv6/

So, if you are using a hard-coded IP address in your FTP or if you are using some API that uses such, then it may lead to issues if the IP isn't in IPv6 form.



[TOPIC: post.html]
#8

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 936 posts
  • Corona SDK

This would explain why it does work on the simulator: the simulator turns off ATS off for all connections, because it needs to be able to simulate all kinds of devices.

 

Some research has shown that I didn't have AAAA-records set for my domain, and so IPv6 was not supported. I'll test tomorrow when the DNS-changes have been propagated to see if that fixes anything. If not, I'll try messing around with ATS exceptions again. I tried this before but maybe I missed something.

 

If that all fails I'm going to check if the versions of "socket.ftp" and "ltn12" that Corona offers support IPv6. Graham's excellent ftp.lua module requires these 2 modules, so these might be a bottleneck as well...



[TOPIC: post.html]
#9

carloscosta

[GLOBAL: userInfoPane.html]
carloscosta
  • Contributor

  • 626 posts
  • Corona SDK

thomas6, if you go network.upload route, php code would be easy since it's a very well known and documented language. Just google around you will find code like this:

file_put_contents("outputfile.txt", file_get_contents("php://input"));

or links like this that can help you:

 

https://gist.github.com/magnetikonline/650e30e485c0f91f2f40



[TOPIC: post.html]
#10

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 936 posts
  • Corona SDK

Hi all, and thanks for the great tips!

 

I'm ashamed to say that after digging and snooping around for a couple of days, I gave up and tried on a friend's iPad. Lo and behold, my exact same old code using Graham Ransons's ftp.lua module worked flawlessly. To cut a long story short, it turned out my iPad was not connecting well to the internet for reasons I don't understand... After connecting to another wi-fi router it suddenly worked as well!

 

So, the problem was not the code, but the damn wi-fi network behaving weirdly all of a sudden!

 

It was good to learn about IPv4 and IPv6, and Apple's move towards the latter, as well as the App Transport Security stuff and how to work around this through build.settings. I'm sure that's going to pop up sometime in the near future so it's good to have a grasp already.

 

Yeah, debugging can be confusing and frustrating sometimes!




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: upload, download, level, data, files, ftp, ios