#import <Foundation/Foundation.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AudioToolbox/AudioToolbox.h>
#include <sys/param.h>
#include <sys/mount.h>
#ifdef __cplusplus
extern "C"
{
#endif
bool CanOpenURL(char* name)
{
    NSURL *appURL = [NSURL URLWithString:[NSString stringWithUTF8String:name]];
    if ([[UIApplication sharedApplication] canOpenURL:appURL])
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

void GotoAppSetting()
{
    NSURL *settingURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if([[UIApplication sharedApplication] canOpenURL:settingURL])
    {
        [[UIApplication sharedApplication] openURL:settingURL];
    }
}
long getFreeSpace() {
	NSDictionary *systemAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()];
    NSString *diskTotalSize = [systemAttributes objectForKey:@"NSFileSystemSize"];
    NSLog(@"totalspace：%@ B", diskTotalSize);
    NSLog(@"totalspace：%.2f GB", [diskTotalSize floatValue]/1024/1024/1024);
    NSString *diskFreeSize = [systemAttributes objectForKey:@"NSFileSystemFreeSize"];
    NSLog(@"freespace：%@ B", diskFreeSize);
    NSLog(@"freespace：%.2f GB", [diskFreeSize floatValue]/1024/1024/1024);
    return [diskFreeSize longLongValue]/(1024 *1024);
  }
    
bool canAttPopup()
{
    if (@available(iOS 14, *))
    {
        return [ATTrackingManager trackingAuthorizationStatus] == ATTrackingManagerAuthorizationStatusNotDetermined;
    }
    return false;
}
    
void EX_C_ATTAuthorize()
{
    if (@available(iOS 14.0, *)){
      [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
          NSLog(@"ATTrackingManagerStatus: %d", (int)status);
          if(ATTrackingManagerAuthorizationStatusAuthorized == status)
          {
              //[FBAdSettings setAdvertiserTrackingEnabled:YES];
          }
          UnitySendMessage("GameManager", "OnATTAuthStatus", [[NSString stringWithFormat:@"%d", (int)status] UTF8String]);
      }];
    }
}
    
int EX_C_UserInterfaceStyle()
{
    if (@available(iOS 14.0, *))
    {
        return (int)[[[UIScreen mainScreen] traitCollection] userInterfaceStyle];
    }
        
    return 0;
}
    
    void EX_C_CallVibrateE(int eID)
    {
        AudioServicesPlaySystemSound(eID);
    }
    
#ifdef __cplusplus
}
#endif
