Issue connecting an iOS build to a google API spreadsheet

Hi there! I am quite new to programming and app development and currently running into issues connecting an iOS build of my app to a google API spreadsheet. For context: I discovered Unity when I was trying to find a way to make a game for a research I will be conducting. The game is designed to nudge certain eating behavior. The players of the game (and thus the participants of my research) will be able to indicate what they are eating (in real life) via buttons in the game. I have used on-click events to enable certain buttons to send live data to a google spreadsheet using google sheets API. In this way, I intend to collect the data I need for the research.

For the android version, I made an APK file which I sent to google drive and then downloaded on an android phone. For the iOS version, this was a little more complicated. I had to borrow a macbook so I could use Xcode. I created a zip file with the iOS version of my game and sent it to google drive. I then downloaded and unzipped it on the macbook and imported it into Xcode. I adjusted some settings and installed the game on my iphone.

This is where I ran into a problem. While tests from my windows laptop and from an android phone worked (and the correct data was sent to the spreadsheet), this did not work when testing on an apple phone (using the iOS version). It seems that this version of the game is unable to access the spreadsheet. I have added some notes of the Xcode debug console in the attached media file (I would have preferred to show more, but I can only add 1 media file to this post). I copied the relevant part of my unity script I used to connect the app to the spreadsheet below. I am not sure what I need to change in my unity project and/or Xcode to fix the issue. In case you know more about this topic/issue, I would greatly appreciate any help :slight_smile:

SCRIPT:

using System;
using System.Collections.Generic;
using System.Linq;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
using System.IO;
using UnityEngine;  // Add this for Debugging
using UnityEngine.Networking; // For UnityWebRequest

public class GoogleSheetsHandler3 : MonoBehaviour
{
    private static readonly string[] Scopes = { SheetsService.Scope.Spreadsheets };
    private const string SpreadsheetId = "MYSPREADSHEET"; // Replace with your Spreadsheet ID
    private SheetsService service;

    public GoogleSheetsHandler3()
    {
        string credentialsPath = Path.Combine(Application.streamingAssetsPath, "MYJSONFILE");

        GoogleCredential credential;

        if (Application.platform == RuntimePlatform.Android)
        {
            // Android: Use UnityWebRequest to read the file
            UnityWebRequest request = UnityWebRequest.Get(credentialsPath);
            request.SendWebRequest();

            while (!request.isDone) { } // Wait for the request to complete

            if (request.result == UnityWebRequest.Result.Success)
            {
                using (var stream = new MemoryStream(request.downloadHandler.data))
                {
                    credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);
                }
            }
            else
            {
                Debug.LogError("Failed to load credentials file on Android: " + request.error);
                return;
            }
        }
        else if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            // iOS: Copy the file to a readable location only once
            string sourcePath = Path.Combine(Application.streamingAssetsPath, "MYJSONFILE");
            string destinationPath = Path.Combine(Application.persistentDataPath, "MYJSONFILE");

            if (!File.Exists(destinationPath))  // Only copy if it doesn't already exist
            {
                // Copy file from StreamingAssets to persistentDataPath
                UnityWebRequest request = UnityWebRequest.Get(sourcePath);
                request.SendWebRequest();

                // Wait for the request to complete
                while (!request.isDone) { }

                if (request.result == UnityWebRequest.Result.Success)
                {
                    File.WriteAllBytes(destinationPath, request.downloadHandler.data);
                    Debug.Log("Credentials copied to: " + destinationPath);
                }
                else
                {
                    Debug.LogError("Failed to copy credentials file on iOS: " + request.error);
                    return;
                }
            }

            // Load the credentials from the persistentDataPath (where it is now copied)
            using (var stream = new FileStream(destinationPath, FileMode.Open, FileAccess.Read))
            {
                credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);
            }
        }
        else
        {
            // Other platforms (Windows, macOS, etc.)
            using (var stream = new FileStream(credentialsPath, FileMode.Open, FileAccess.Read))
            {
                credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);
            }
        }

        // Initialize Google Sheets API service
        service = new SheetsService(new BaseClientService.Initializer
        {
            HttpClientInitializer = credential,
            ApplicationName = "Meat Consumption Data App Demo",
        });

        Debug.Log("Google Sheets API service initialized successfully.");
    }