Im trying to create a plugin for unity game on ios platform
For some reason the second time i try to access the static property shared instance i get Thread 1: EXC_BAD_ACCESS (code=1, address=0xb21c290b0) on line => auto *instance = [[AppattestPluginWrapper sharedInstance] appAttestPlugin];
Weird thing is when i use break point in the sharedInstance property,the value returned isn't nil so it looks like something in the assignment of the var *instance crashes and i can't figure out why.
#import "UnityAppController.h"
#import <Foundation/Foundation.h>
#import "UnityFramework/UnityFramework-Swift.h"
@interface AppattestPluginWrapper: NSObject
{
}
@property (nonatomic, strong) AppAttestPlugin *appAttestPlugin;
@end
@implementation AppattestPluginWrapper
(id)sharedInstance {
static AppattestPluginWrapper *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
sharedInstance.appAttestPlugin = [[AppAttestPlugin alloc] init];
});
return sharedInstance;
}
@end
extern "C"{
void _generateAppAttestKeyId(){
auto *instance = [[AppattestPluginWrapper sharedInstance] appAttestPlugin];
[instance generateAppAttestKeyWithCompletion: ^(NSString * response, NSError * error){
if(error){
UnitySendMessage("iOSListener", "OnAppAttestKeyGenerationFailed", [[error localizedDescription] UTF8String]);
}
else if(response){
UnitySendMessage("iOSListener","OnAppAttestKeyGenerated", [response UTF8String]);
}
}];
}
}
CodePudding user response:
The cause for this behaviour was a crash that corrupted the shared instance, for some reason there was no indicator for the corruption and it took some time to detect the issue that was related to the unity code.