- Home /
WebCamTexture IOS crashing?
Hello everyone, i'm having sort of a trouble here with iOS and WebCamTexture's. So the code below works perfectly on android, but once i deploy it on iOS it will crash on startup, and i know that the problem is this script, because when i turn it off, the iOS runs then, so what am i doing wrong here, that it's crashing, and please if you have any other code that works on iOS please can you share it with me. (in Xcode it gives me an error of Thread 35 : Signal SIGABRT), any thought of you'rs could solve my problem and help me on my project. Thanks a lot!.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System;
public class CameraAdapter : MonoBehaviour
{
/// Meta reference to the camera
/// </summary>
public Material CameraMaterial = null;
/// <summary>
/// The number of frames per second
/// </summary>
private int m_framesPerSecond = 0;
/// <summary>
/// The current frame count
/// </summary>
private int m_frameCount = 0;
/// <summary>
/// The frames timer
/// </summary>
private DateTime m_timerFrames = DateTime.MinValue;
/// <summary>
/// The selected device index
/// </summary>
private int m_indexDevice = -1;
/// <summary>
/// The web cam texture
/// </summary>
private WebCamTexture m_texture = null;
public Renderer imgja;
public GameObject IMgja;
private int index;
public int itebi = 0;
public GameObject CameraMAT;
private int kk = 0;
// Use this for initialization
void Start()
{
Application.RequestUserAuthorization(UserAuthorization.WebCam);
}
public void TakePic()
{
IMgja.SetActive(true);
Texture2D photo = new Texture2D(m_texture.width, m_texture.height);
photo.SetPixels(m_texture.GetPixels());
photo.Apply();
imgja.material.mainTexture = photo;
CameraMAT.SetActive(false);
}
public void SwichCam()
{
if (itebi == 0)
{
itebi = 1;
}
else
{
itebi = 0;
}
}
void OnGUI()
{
try
{
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
var device = WebCamTexture.devices[index];
//Has permission
if (null == WebCamTexture.devices)
{
GUILayout.Label("Null web cam devices");
//No Camera
}
else
{
for (index = 0; index < WebCamTexture.devices.Length; ++index)
{
Debug.Log(index);
if (itebi == 0)
{
device = WebCamTexture.devices[0];
}
else
{
device = WebCamTexture.devices[1];
}
if (string.IsNullOrEmpty(device.name))
{
continue;
}
}
m_indexDevice = index;
// stop playing
if (null != m_texture)
{
if (m_texture.isPlaying)
{
m_texture.Stop();
}
}
// destroy the old texture
if (null != m_texture)
{
UnityEngine.Object.DestroyImmediate(m_texture, true);
}
// use the device name
m_texture = new WebCamTexture(device.name);
if (kk == 0)
{
m_texture.Play();
}
// start playing
// assign the texture
CameraMaterial.mainTexture = m_texture;
}
}
else
{
Application.RequestUserAuthorization(UserAuthorization.WebCam);
GUILayout.Label("Pending WebCam Authorization...");
}
}
catch
{
}
}
public void StopCam()
{
kk = 1;
m_texture.Stop();
}
public void BackCam()
{
itebi = 0;
index = 0;
//Debug.Log(index);
}
// Update is called once per frame
void Update()
{
if (null != m_texture &&
m_texture.didUpdateThisFrame)
{
CameraMaterial.mainTexture = m_texture;
}
}
}
Answer by hydrox1 · Oct 01, 2018 at 08:28 PM
Nevermind, i found the solution, all you need to do is go to the info.plist file on the Xcode source and add these two lines , and it will fix the soludtion since in Application.RequestUserAuth doesn't seem to work on IOS 10..
`<key>NSCameraUsageDescription</key>
<string>${PRODUCT_NAME} Camera Usage</string>
<key>NSMicrophoneUsageDescription</key>
<string>${PRODUCT_NAME} Microphone Usage</string>`