- Home /
iPhone: Update Assets from Web?
I'm working on a project where the client wants to be able to update certain text based data assets and maybe select image assets that are stored locally on the phone without needing to issue a formal application update through the iTunes Store. Is this possible?
Assuming any kind of update is possiblem, if there were new icon images to go with things added to the text assets, would it be possible to store entirely new assets?
I'm totally new to iPhone development, and fairly new to Unity as well, so any insight would be appreciated.
Answer by spinaljack · Jul 20, 2010 at 12:13 AM
You can have your app look for new asset bundles from a server and download them if necessary using the WWW class.
From the iphone docs:
var download : WWW;
var url = "http://somehost/somepath/someassetbundle.assetbundle";
download = new WWW (url);
yield download;
assetBundle = download.assetBundle;
if (assetBundle != null)
{
// Alternatively you can also load an asset by name (assetBundle.Load("my asset name"))
var go : Object = assetBundle.mainAsset;
if (go != null)
instanced = Instantiate(go);
else
Debug.Log("Couldnt load resource");
}
else
{
Debug.Log("Couldnt load resource");
}
You can then save the data to a documents folder on the device
Again from the docs:
public static string GetiPhoneDocumentsPath ()
{
// Your game has read+write access to /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents
// Application.dataPath returns
// /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data
// Strip "/Data" from path
string path = Application.dataPath.Substring (0, Application.dataPath.Length - 5);
// Strip application name
path = path.Substring(0, path.LastIndexOf('/'));
return path + "/Documents";
}
You can also simply download a texture or some text from a website and use them directly in your game without using asset bundles if you prefer. You do this by setting up a new WWW and storing the returned text as a string with www.data
I need to test this, of course, but I'm certainly giving you the answer for now! Thanks so much! Super helpful!
One brief additional question, if you happen to know, is that documents folder backed-up with the rest of the iPhone data when iTunes does it backup?
Backup saves data such as music, applications, podcasts, videos, ringtones, photos, notes, email account settings, contacts, calendars, and bookmarks. So yes, the whole folder.