Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by dryheat70 · Nov 27, 2014 at 08:21 PM · iosstreamingassetsopenurl

iOS Loading Local PDF/HTML from StreamingAssets

In our standalone build, we use Application.OpenURL to open our local helpsystem (bunch of loose html files) and our training reference system (bunch of loose pdf files).

We have now been tasked with putting our application on on iPad and I noticed it doesn't appear we can use OpenURL with assets in StreamingAssets like we can on standalone.

After looking at many other posts, it appears (?) we might be able to copy these files from streamingassets to persistentdata and then use Application.OpenURL, but I've yet to get it working.

For testing, I have a simple pdf and html file that reside in the root of StreamingAssets and am using the following code to try to open either one. Has anybody gotten this to work? I've seen some say it used to work, but no more... (I'm on Unity 4.6 RC2 and iOS 8.0).

With the following code, the files exist in streamingassets, the www1.bytesDownloaded field is correct after getting via WWW, and the files are copied to persistentDataPath correctly. I just can't seem to get the Application.OpenURL to work with either the html or the pdf... I assume I'm supposed to use the file:// protocol schema but maybe this is the issue. Any pointers are greatly appreciated.

     public IEnumerator LoadLocal()
     {        
         string fromPath = Application.streamingAssetsPath + "/";
         string toPath = Application.persistentDataPath + "/";
         string pdfToLoad = "simple.pdf";
         string htmlToLoad = "simplehtml.html";
 
         if(File.Exists(fromPath + pdfToLoad))
         {
             UnityEngine.Debug.Log(string.Format("Sees {0} in streamingassets\n", pdfToLoad));
         }
         if(File.Exists(fromPath + htmlToLoad))
         {
             UnityEngine.Debug.Log(string.Format("Sees {0} in streamingassets\n", htmlToLoad));
         }
 
         WWW www1 = new WWW("file://" + fromPath + pdfToLoad);        
         yield return www1;
             
         UnityEngine.Debug.Log("Sees isDone as : " + www1.isDone);
         UnityEngine.Debug.Log("Sees bytesDownloaded as : " + www1.bytesDownloaded);
         if (www1.error != null)
         {
             UnityEngine.Debug.Log("Error in www\n");
             UnityEngine.Debug.Log(www1.error);
         }
 
         File.WriteAllBytes(toPath + pdfToLoad , www1.bytes);
         UnityEngine.Debug.Log(string.Format("Wrote pdf to {0}\n", toPath + pdfToLoad\n));
         
         if(File.Exists(toPath + pdfToLoad))
         {
             UnityEngine.Debug.Log("Sees pdf in written to persistentdata location\n");
         }            
         UnityEngine.Debug.Log("trying to open " + toPath + pdfToLoad);
         // none of these work, even if I change to http:// when using the htmlToLoad
         //    Application.OpenURL("file://" + toPath + pdfToLoad);
         //    Application.OpenURL("file:///" + toPath + pdfToLoad);                            
         //    Application.OpenURL("File:///" + toPath + pdfToLoad);                            
     }





SOLUTION

It didn't look this was going to be possible or ideal, so the solution for us involved writing native iOS plugins following Unity's docs that used UIWebView (for local html files) and UIDocumentInteractionController (for local pdf files) to view the documents without having to leave the app. We were able to load the files from their respective Application.dataPath + "/Raw" locations.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DottorFeelgood · Aug 18, 2015 at 01:21 PM 0
Share

Hi, that is very interesting. Would you share some code?

avatar image martejpad DottorFeelgood · Oct 27, 2017 at 02:46 PM 0
Share

Hi @DottorFeelgood, I've been fighting with this all morning and finally got it working. If you're still interested have a look at my answer here: http://answers.unity3d.com/answers/1426652/view.html

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Launch an iOS app with options C# 0 Answers

Unable to load the image file from streaming assets folder 1 Answer

iOS won't load streaming asset 2 Answers

Load Xml from StreamingAssets on Start for iOs mobile device 1 Answer

OpenURL opens app in same window 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges