Getting iPhone Data - ios

I own a wholesale distribution business focusing on iPhones. I am also an apple developer. I want to create a database that stores all device information by simply installing the app. I understand that this would completely be rejected if I were to send it off to the App Store but this is just in house and I will install simply with Apple Configurator.
I have found online that you no longer can get access to UDID and IMEI numbers. Is there a way for me to do this, not worrying about getting into the app store review policies. I just need an NSString for basic information about the device.
UDID
IMEI
Carrier
iOS Version
Storage Capacity
Model
I know how to find iOS Version and Model but cannot find any others.

You can no longer get UDID or IMEI.
To get the other data:
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
// carrier info
CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netinfo subscriberCellularProvider];
NSLog(#"Carrier Name: %#", [carrier carrierName]);
// Misc device info
UIDevice *myDevice = [UIDevice currentDevice];
NSString *deviceName = myDevice.Name;
NSString *deviceSystemName = myDevice.systemName;
NSString *deviceOSVersion = myDevice.systemVersion;
NSString *deviceModel = myDevice.model;
// Get the capacity of the device.
NSError *error = nil;
NSArray * const paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary * const pathAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths firstObject] error:&error];
NSAssert(pathAttributes, #"");
NSNumber * const fileSystemSizeInBytes = [pathAttributes objectForKey: NSFileSystemFreeSize];
const long long numberOfBytesRemaining = [fileSystemSizeInBytes longLongValue];
NSByteCountFormatter *byteCountFormatter = [[NSByteCountFormatter alloc] init];
NSString *formattedNmberOfBytesRemaining = [byteCountFormatter stringFromByteCount:numberOfBytesRemaining];
NSString *formattedNmberOfBytesTotal = [byteCountFormatter stringFromByteCount:fileSystemSizeInBytes ];

Related

NSFileSystemSize return factory memory size on iOS 10.3+ - Objective-c

Since the release of iOS 10.3 and APFS for iPhone, getting the device memory size with :
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSUInteger totalDeviceSpace = [fileSystemSizeInBytes unsignedLongLongValue];
NSUInteger totalDeviceFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
return the factory memory size. For example, on iOS 10.2, I got 11,60 Go for a 16 Go device. On 10.3+ I get 15,99 Go (result formatted with stringFromByteCount).
How could I do to restore the old behaviour ?
Thanks and have a nice day !
You might get total space and free space in this way:
NSError *error = nil;
NSArray *mypath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *myDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[mypath lastObject] error: &error];
NSNumber *fileSystemSizeInBytes = [myDictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [myDictionary objectForKey:NSFileSystemFreeSize];
uint64_t totalSpaceSize = [fileSystemSizeInBytes unsignedLongLongValue];
uint64_t totalFreeSpaceSize = [freeFileSystemSizeInBytes unsignedLongLongValue];
So it appear that it's now the desired comportment (tested in iOS 10.3, 10.3.1, 10.3.2 and iOS 11 beta 1 & 2).
To adjust the result depending on the installed iOS versions I do :
NSOperatingSystemVersion ios10_3 = (NSOperatingSystemVersion){10, 3, 0};
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios10_3]) {
//User have at least 10.3 installed
}else {
//below iOS 10.3
}

How to read and store System Log messages in IOS using Objective-C

My intention is to read all the system log messages pertaining to my application(all those log messages present inside the system.log file), and store it in a log file within the app's Document folder.
I went through this code and used this answer.
Here is my code:
NSDate *currentDate = [[NSDate alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:[NSString stringWithFormat: #"dd-MM-yyyy-HHmmss"]];
NSString *logFileName = [[formatter stringFromDate:currentDate] stringByAppendingString:#".log"];
NSError *error;
NSMutableString *content = [[NSMutableString alloc] init];
aslmsg q, m;
int i;
const char *key, *val;
q = asl_new(ASL_TYPE_QUERY);
aslresponse r = asl_search(NULL, q);
while (NULL != (m = asl_next(r)))
{
NSMutableDictionary *tmpDict = [NSMutableDictionary dictionary];
for (i = 0; (NULL != (key = asl_key(m, i))); i++)
{
NSString *keyString = [NSString stringWithUTF8String:(char *)key];
val = asl_get(m, key);
NSString *string = [NSString stringWithUTF8String:val];
[tmpDict setObject:string forKey:keyString];
}
[content appendString:[NSString stringWithFormat:#"%#",tmpDict]];
}
asl_release(r);
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:logFileName];
[[NSString stringWithString:content] writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
This is just a part of code of my IOS app. I am running my app on the IOS Simulator.
The log files gets successfully created. It has some content which is predominantly JSON.
However, the file does not have those log messages which I outputting through NSLog, yet those log messages are present inside the System's log file.
I am quite new to IOS Development. As stated, my purpose to access the System's log files. So I want to capture each log message and save it into my personal directory.
I searched a lot on this Stackoverflow. However, I haven't found the exact thread which could help me on this. Can anyone guide me appropriately?
(I hope this question isn't duplicated.)
I guess you want them to check them later in case you find an error. Maybe you can try Bugfender (http://bugfender.com), it's a tool we have created to get the logs from our customers while developing apps.
With it, you are going to be able to get also all NSLog calls.
The answers you have checked are the right way to do it if you don't want to use Bugfender. In our case we are using the functions documented here

why my app is rejected from appstore although i am not using icloud

I did not use any icloud storage
Reasons 2.23: Apps must follow the iOS Data Storage Guidelines or they will be rejected
----- 2.23 -----

We found that your app does not follow the iOS Data Storage Guidelines, which is required per the App Store Review Guidelines.

In particular, we found that on launch and/or content download, your app stores 21.12 MB. To check how much data your app is storing:

- Install and launch your app
- Go to Settings > iCloud > Storage & Backup > Manage Storage 
- If necessary, tap "Show all apps" 
- Check your app's storage

The iOS Data Storage Guidelines indicate that only content that the user creates using your app, e.g., documents, new files, edits, etc., should be backed up by iCloud. 

Temporary files used by your app should only be stored in the /tmp directory; please remember to delete the files stored in this location when the user exits the app.

Data that can be recreated but must persist for proper functioning of your app - or because customers expect it to be available for offline use - should be marked with the "do not back up" attribute. 

For NSURL objects, add the NSURLIsExcludedFromBackupKey attribute to prevent the corresponding file from being backed up. For CFURLRef objects, use the corresponding kCFURLIsExcludedFromBackupKey attribute. 

For more information, please see Technical Q&A 1719: How do I prevent files from being backed up to iCloud and iTunes?.
To Store data offline into Sqlite my function is
+ (NSString*)saveImageInDocuments:(UIImage*)senderImage {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDate *selected = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"ddmmyyyyhhmmss"];
NSString *imgName = [dateFormat stringFromDate:selected];
imgName = [NSString stringWithFormat:#"%#.jpg",imgName];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:imgName];
UIImage *image = senderImage;
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
[imageData writeToFile:savedImagePath atomically:YES];
NSLog(#"path is... %#",savedImagePath);
return imgName;
}
And to get data offline from sqlite i am using this function
+ (UIImage*)getImageFromDocuments:(NSString*)senderImageName {
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:senderImageName];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL fileExist = [fileManager fileExistsAtPath:getImagePath]; // Returns a BOOL
UIImage *img = [[UIImage alloc] init];
if(fileExist)
{
img = [[UIImage alloc] init];
img = [UIImage imageWithContentsOfFile:getImagePath];
}
NSLog(#"path is... %#",getImagePath);
return img;
}
You have to set a flags for files which you don't want to sync on iCloud. By default iOS Sync. app data on iCloud if device settings allow it.
Use this method to skip files from backup
- (BOOL)addSkipBackupAttributeToItemAtURL: (NSURL *)URL {
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version > 5.0) {
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
}
return NO;
}
[self addSkipBackupAttributeToItemAtURL:[[NSURL alloc] initFileURLWithPath:"YOURFILEPATH"]];

Obfuscate iPhone Password

If I need to obfuscate an iPhone password that is hardcode (Oauth Client Identifier and Client Secret), would this be a way to do it?
NSString *a = #"a";
NSString *b = #"b";
NSString *c = #"c";
NSString *d = #"d";
NSString *e = #"e";
NSString *f = #"f";
NSString *g = #"g";
NSString *h = #"h";
NSString *i = #"i";
/* hidden */
NSString *w = #"w";
NSString *x = #"x";
NSString *y = #"y";
NSString *z = #"z";
NSString *pwd = [NSString stringWithFormat:#"%#%#%#%#%#%#%#%#", p,a,s,s,w,o,r,d];
I know obfuscate isn't recommended but after reading this OAuth secrets in mobile apps it seems like the only way.
If you compile with clang -O3, only the letters that are actually used in the password get included in the .o file. You should include some code that pretends to use the rest of the alphabet, such as another call to + stringWithFormat whose results are ignored.
You could always encrypt the text in question offline, store the encrypted version in the app, then at the point where you need it, decrypt it. That way it (at least) isn't in plain text in the app. Even your mechanism above will likely produce a pattern in the binary.

How to get installed apps on iPhone

How can I get the details of all the installed apps on my iPhone device, and the details of all the applications which are running in background? Thanks in advance.
Yes, we can get the list of Installed Application.
NSDictionary *cacheDict;
NSDictionary *user;
static NSString *const cacheFileName = #"com.apple.mobile.installation.plist";
NSString *relativeCachePath = [[#"Library" stringByAppendingPathComponent: #"Caches"] stringByAppendingPathComponent: cacheFileName];
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent: #"../.."] stringByAppendingPathComponent: relativeCachePath];
cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];
user = [cacheDict objectForKey: #"User"];
user Dict will give us all the information about installed Application.

Resources