- Home /
Couldn't get image loaded from file in IOS
Hi, I am trying to load facebook profile picture that i have saved into device. The code is working fine in Android but not IOS. I was suffering this problem for many days. So here is my code, please help me.
using UnityEngine;
using System.Collections;
using System.IO;
using UnityEngine.UI;
public class UserProfilePicture : MonoBehaviour {
public RawImage profilePicture;
private Texture2D texture,text;
void FixedUpdate(){
if (FbSetup.userInfoLoaded) {
if(SPFacebook.instance.userInfo.GetProfileImage(FacebookProfileImageSize.square) != null) {
text = SPFacebook.instance.userInfo.GetProfileImage(FacebookProfileImageSize.square);
}
}
byte[] textureByte = text.EncodeToPNG ();
File.WriteAllBytes (Path.Combine(Application.persistentDataPath,"profilePicture.png"),textureByte);
Debug.Log("Save path: " + Application.persistentDataPath + Path.DirectorySeparatorChar + "profilePicture.png");
if(File.Exists(Application.persistentDataPath + Path.DirectorySeparatorChar + "profilePicture.png")){
Debug.Log("Texture saved");
}
}
void Update(){
StartCoroutine (Control ());
profilePicture.texture = texture as Texture;
}
IEnumerator Control(){
WWW pictureUrl;
pictureUrl = new WWW(System.Uri.EscapeUriString("file://" + Path.Combine(Application.persistentDataPath,"profilePicture.png")));
yield return new WaitForEndOfFrame();
texture = pictureUrl.texture;
Debug.Log("Loaded path: " + Path.Combine(Application.persistentDataPath,"profilePicture.png"));
}
void OnEnable(){
if (GLobal.playAsGuest) {
this.gameObject.SetActive(false);
}
else{
this.gameObject.SetActive(true);
}
}
}
Appreciate for your help, thanks!
Comment
Your answer
Follow this Question
Related Questions
iOS - Saving Data (Image) 1 Answer
Blurry / Pixelated images on Unity 3D for iOS, 1 Answer
Question on "Missing Retina 4-inch launch image" with Unity Free 0 Answers
What would cause my launch screen image to be black for the few first seconds on iOS? 0 Answers
iOS launch image is stretched for a brief second on start 1 Answer