Unable to open mobileconfig file in Safari ios dev

2019-09-01 06:09发布

问题:

I am making an app where it downloads mobileconfig from my server to my ios app. And I've created a server running background and used openUrl to open it in the safari so user can install the profile. But it only works in the simulator but not on my device.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://localhost:12345/file.mobileconfig"]];

where file.mobileconfig is downloaded in the root(localhost).

A.I ve implemented this solution: Open .mobileconfig file saved in application in safari ios but it works fine on the simulator but it doesn't fetch the files when I run it in the device.

B. I ve made a directory in the app as root(localhost folder). And Downloaded files are saved in the localhost.


Resolved

I was trying to fetch the data from app sandbox i.e xyz.app/Web/file which is not possible because of sandboxing.

step 1: Check for file existence: How to check if a file exists in Documents folder?

In my code I made "Web" as root and download folder when I checked for download files existences it didn't exist.

Step 2:I have made Documents as root and files are downloaded to the Documents which is publicly accessible.

Step 3: I checked on my devices it was working.

回答1:

That's because localhost inside the device is the device itself. You have to replace localhost with the LAN ip address of your computer (and it's not 127.0.0.1).