Created
June 11, 2018 17:35
-
-
Save robsondepaula/84063507973e7e3ffcfbf31e098144c7 to your computer and use it in GitHub Desktop.
A minimal Unity Native Plugin for iOS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <UIKit/UIKit.h> | |
#import <CoreTelephony/CTCarrier.h> | |
#import <CoreTelephony/CTTelephonyNetworkInfo.h> | |
#import "UnityInterface.h" | |
// Required to return strings to Unity | |
char* cStringCopy(const char* string) | |
{ | |
if (string == NULL) | |
{ | |
return NULL; | |
} | |
char* res = (char*)malloc(strlen(string) + 1); | |
strcpy(res, string); | |
return res; | |
} | |
static uint64_t const THIRTY_MEGA_IN_BYTES = 30 * 1048576; | |
extern "C" { | |
bool availableFileSystemSpace() { | |
uint64_t totalSpace = 0; | |
uint64_t totalFreeSpace = THIRTY_MEGA_IN_BYTES; | |
__autoreleasing NSError *error = nil; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error]; | |
if (dictionary) | |
{ | |
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize]; | |
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize]; | |
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue]; | |
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue]; | |
} | |
return totalFreeSpace > THIRTY_MEGA_IN_BYTES; | |
} | |
char* getDeviceName() { | |
NSString* devNameString = [[UIDevice currentDevice] name]; | |
return cStringCopy([devNameString UTF8String]); | |
} | |
char* getUserLocationByNetwork() { | |
CTTelephonyNetworkInfo* network_Info = [CTTelephonyNetworkInfo new]; | |
CTCarrier* carrier = network_Info.subscriberCellularProvider; | |
NSString* userLocationString = carrier.isoCountryCode; | |
userLocationString = [userLocationString uppercaseString]; | |
return cStringCopy([userLocationString UTF8String]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment