My app was created in Unity for Mac and iOS using C#. I have also created an Apple TV version, but need to connect to iCloud for the save since that seems to be the only way to save on that medium. I created a plugin along with a wrapper to link it to the C# project but I am getting an xCode error: Linker command failed with exit code 1 (use -v to see invocation)
Expanding the debug info, it was the iCloud Wrapper causing the problem, stating there were "Undefined Symbols".
Here's the wrapper code:
// CloudKitWrapper.cs
using UnityEngine;
using System.Runtime.InteropServices;
public class CloudKitWrapper : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void initCloudKit();
[DllImport("__Internal")]
private static extern void performCloudKitOperation();
public static void InitCloudKit()
{
#if UNITY_TVOS && !UNITY_EDITOR
initCloudKit();
#endif
}
public static void PerformCloudKitOperation()
{
#if UNITY_TVOS && !UNITY_EDITOR
performCloudKitOperation();
#endif
}
}
And the Plugin:
CloudKitPlugin.h
@import Foundation
@import CloudKit
@interface CloudKitPlugin : NSObject
+ (void)initCloudKit;
+ (void)performSomeCloudKitOperation;
@end
And:
CloudKitPlugin.m
#import "CloudKitPlugin.h"
@implementation CloudKitPlugin
+ (void)initCloudKit {
#import "CloudKitPlugin.h"
let cloudStoreLocation = URL(fileURLWithPath: “iCloud.com.BevvyOfFun.LandonsHopeQuest”)
let cloudStoreDescription =
NSPersistentStoreDescription(url: cloudStoreLocation)
cloudStoreDescription.configuration = "Cloud"
cloudStoreDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: “com.BevvyOfFun.LandonsHopeQuest.container”)
let options = NSPersistentCloudKitContainerSchemaInitializationOptions()
try? container.initializeCloudKitSchema(options: options)
return container
}
+ (void)performCloudKitOperation {
lazy var persistentContainer: NSPersistentCloudKitContainer = {
let container = NSPersistentCloudKitContainer(name: “iCloud.com.BevvyOfFun.LandonsHopeQuest”)
container.loadPersistentStores(completionHandler: { })
let options = NSPersistentCloudKitContainerSchemaInitializationOptions()
try? container.initializeCloudKitSchema(options: options)
return container
}()
}
@end
if(container != null)
{
container.initializeCloudKitSchema(options: options)
return container
}
I'd appreciate any help you can give to solve this problem. Thanks!
This wouldn't run on xCode since the wrapper could not link to the plugin.