How to get logs from the ipa installed on my iOS device? - ios

Since I am a beginner in iOS development I am in a learning phase so please bear with this question.
I got an ipa from the client to install on my iPhone . However while using the app after installing through .ipa I got an error , can someone tell how can I get the logs from ipa file so that I can understand this error and pass logs to the api team? I know I can get by connecting the device and running/building through xcode directly but unfortunately code is with client and he generates the ipa. Is it possible to get the logs through ipa? I tried to use View Device Logs from Window -> Device and Simulators by selecting my device but those logs are not which I want
I found several answers like adding the below code in application:didFinishLaunchingWithOptions
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:#"%#.log",[NSDate date]];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
Is it possible to get logs from ipa file as we get from APK file in Android? If yes, can someone tell how to get the logs from ipa file?

Related

Is there an actual iPhone App cache.db available to view just like a simulator?

I have the following code to find the iPhone's cache.db.
NSArray* paths1 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* cacheDir = [paths1 objectAtIndex:0];
NSLog(#"cache directory%#",cacheDir);
Which prints out this location.
/var/mobile/Containers/Data/Application/02DAB563-8FBC-44E2-854A-B8A1F8B90635/Library/Caches
However, I can't find the cache.db.
This is strange because I can find the cache.db for simulators, but not iPhone. Is the cache.db hidden for actual iPhone devices. Any help is appreciated.
The file will be on the device, not your local file system.

iOS: When I open my app from iMazing, how to hide and protect from read and protect from copy on the mac a specific folder?

With Swift or with Obj-C, I have done an app, and I store sensitive data in a specific folder in the app. Now, I would like the user not be able to see that folder and not able to copy it on his computer, or the best, to hide it with software like iMazing for example.
I tried to add a ".", this is not a solution at all: How to hide folder in NSDocumentsDirectory and disallow backup via iTunes & iCloud
I tried to store it in the Library folder, this is not a solution too, as it is accessible in iMazing: How to hide folders created in Document Directory in ios?
I don't want to use the Application supports iTunes file sharing because I need to access to the documents folder from the app with iMazing.
Does exist an intelligent and subtil solution that allows to store some files in the iPad not accessible with iMazing and not carried to the extreme as the "all or nothing" Application supports iTunes file sharing option?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error;
if (! [[NSFileManager defaultManager] fileExistsAtPath:libraryDirectory isDirectory:&isDir] && isDir == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:libraryDirectory withIntermediateDirectories:NO attributes:nil error:&error];
}
NSString *pathLibToCreate = [libraryDirectory stringByAppendingPathComponent:#"testDoc"];
NSString *pathDocToCreate = [[self documentsDirectory] stringByAppendingPathComponent:#"testDoc"];
if (![[NSFileManager defaultManager] fileExistsAtPath:pathLibToCreate]) {
[[NSFileManager defaultManager] createDirectoryAtPath:pathLibToCreate withIntermediateDirectories:NO attributes:nil error:&error];
}
if ([[NSFileManager defaultManager] fileExistsAtPath:pathDocToCreate]) {
[[NSFileManager defaultManager] removeItemAtPath:pathDocToCreate error:nil];
}
NSError *copyError = nil;
if (![[NSFileManager defaultManager] copyItemAtPath:pathLibToCreate toPath:pathDocToCreate error:&copyError]) {
NSLog(#"Error copying files: %#", [copyError localizedDescription]);
}
Thanks in advance.
If you use "File Sharing" permission to NO and if you use a distribution profile, you won't be able to view your files in Amazing.
I guess that it is because you use a developer profile for your app and then you're able to view these files.
I think this is not possible, at least if an user has a jailbroken device where he has access to all files on the system.
To prevent the user from having access to the content of a file, one option could be to encrypt the content of the file. Using the CommonCryptor framework that should be an easy task.
For encrypted databases you could use SQLCipher.
I'm one of the devs of iMazing. Indeed, the accepted answer is correct: iMazing and other similar tools will give access to the app's sandbox when in development. But there are 3 more cases to be aware of:
Jailbroken devices
iMazing will display all files, read/write access.
Devices running a version of iOS prior to iOS 8.3
Same here - before iOS 8.3, we could have access to app sandboxes, read/write too.
Access via iTunes backup
iMazing and similar tools have backup browsers which will let users see app sandboxes. Library and Documents folders, not Caches or tmp. If you really want to be safe, you'll need to explicitly exclude files from the backup. Of course, this has substantial drawbacks...

File not found on iOS device, but found in Simulator

When I run my application on the simulator I found the path of file using following code:
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSLog(#"%#",basePath);
}
simulator output:
file:///Users/username/Library/Application Support/iPhone Simulator/7.0.3/Applications/E7816FF6-7E6A-4606-917E-E74CDB574EC8/Documents/images/20140306113538.png
And same code when I run in my device I found output with:
Device output:
file:///var/mobile/Applications/2D86A03F-C239-4B57-849F-019BCDCA8543/Documents/images/20140306114536.png
And when I checked, file was store in documents.
When I load this url in browser with path of simulator(which I get from simulator output) is loaded in browser.
But path of device(which I get from device output) it showing error in browser with file not found.
like: Firefox can't find the file at /var/mobile/Applications/2D86A03F-C239-4B57-849F-019BCDCA8543/Documents/image/20140306114536.png.
Only just because of this reason I am not able to send file from my device on my server using web service.
Xcode Version: 5.0.2
Device: iPhone 4(iOS 7.0.6)
Any One please help.
Because you are trying to load file from your device which is not available on your system.
And your simulator directory is exist on your system thats why its loading file from your system.
So its better you can browse files from your device and copy into your system using following software
iExplorer
Why do your folder names different ?
for simulator it is "images" and for device it is "image".
Also closely check case sensitivity, since I also had faced similar problem for asset names. MAC file system searches with case insensitivity so simulator may be finding this file. Whereas iOS device file system is case-sensitive.

iOS 7 Error creating folder after App update

I got a real strange problem with an iOS app I'm currently working at. The effect only exists if I test the app using ad hoc distribution. After updating the app (it has to be installed before) it wasn't working correctly. I could track the error down and it is caused by following line of code:
[fileManager createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:nil error:&error];
Now you could say, of course: Don't ever write to the app bundle itself, but the base path is the Documents folder via:
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
imgDir = [docsDir stringByAppendingPathComponent:#"images"];
folder = [imgDir stringByAppendingPathComponent:md5]; // md5-Hash is created before
The complete error message (logged to iphone system log) is:
Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x14d44f30 {NSFilePath=/var/mobile/Applications/280C6D36-3667-4589-A74F-42F3F17ABA71/Documents/images/39b6cd45a05a2276ef065b2ecf33b1eb, NSUnderlyingError=0x14d4e340 "The operation couldn’t be completed. Operation not permitted"}
The interesting thing is, as I noted, if I delete the app before installing via ad hoc distribution (Testflight to a iPhone 5 with iOS 7.0.4) the folder is created and the App works as expected. The only references I could find were developers not using stringByAppendingPathComponent or writing directly to the app bundle. Maybe anybody else got the problem or has an idea?
I finally found the reason why the folder could not be created. Afterwards it seems pretty simple and stupid, but if you could take a look at the complete source code you would unterstand how this could happen. In my defense I have to say that I came to this project for further development because the original developer left the project. For your better understanding I simplified the code a lot.
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
imgDir = [docsDir stringByAppendingPathComponent:#"images"];
The imgDir was actually saved in userPreferences and a proxy class always returned the saved path, which is a really bad idea. During the update process the app gets a new guid which reflects in the apps documents path. So trying to create a folder in the previous version documents folder had to fail as it doesn't exist anymore. I corrected the code to never save the path and always return the current one with the code above.

Logging data on device and retrieving the log

On a debug build in Xcode, regardless of whether I am using the simulator or an actual device, NSLog, printf, fprintf assert and NSAssert statements come out on the console
If I now run a release build on the device (say I send a test flight build and big it up on my iPhone; this will be a release build), which of these (if any) are getting recorded?
And how do I retrieve the log?
Does NSLog actually output something on release build? What is the determining factor? Whether it is writing to stdout or stderr? is only stderr written to device log? Does this mean I have to use fprintf? Is ANYTHING written to device log? is there even such a thing? If so, how to pick it up?
Could someone clarify the situation?
In Xcode 6.1.1, you can view the NSLog output by doing the following. However, I'm not sure if it lets you see logs from too far back in time. I've only seen it go back up to a couple hours.
In any case, here are the steps:
In Xcode, go to Window -> Devices.
Select your device in the left panel.
Click the little arrow as shown in the screenshot below.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:#"%#.log",[NSDate date]];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
Just add this block of code in application:didFinishLaunchingWithOptions method in the app delegate file and it will create a log file in app document directory on iPhone which logs all console log events. You need to import this file from iTunes to see all console events.
Note: In the .plist file make sure that Application supports iTunes file sharing is exists and is set to YES so that you can access through iTunes.
To get Logfiles :
Launch itunes, after your device has connected select Apps - select your App - in Augument Document you will get your file. You can then save it to your disk
In swift 4.0+, the code of Shyl will changes to,
var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
let fileName = "\(Date()).log"
let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName)
freopen(logFilePath.cString(using: String.Encoding.ascii)!, "a+", stderr)
all other process are same that explained by Shyl
Just add this block of code in application:didFinishLaunchingWithOptions method in the app delegate file and it will create a log file in app document directory on iPhone which logs all console log events. You need to import this file from iTunes to see all console events.
Note: In the .plist file make sure that Application supports iTunes file sharing exists and is set to YES so that you can access
through iTunes.
To get Logfiles : Launch iTunes, after your device has connected
select Apps - select your App - in Augument Document you will get your
file. You can then save it to your disk
NSLog is written to device log in production release and you can check this by connecting your iPhone to your system and using Organizer. Select your iPhone in the organizer, click Device Logs. You would see all NSLog outputs in the log.
I found this link from APPLE very informative and complete.
It pretty much gives you all the options to see or access logs of the device whether or not they are connected to your dev machine.
https://developer.apple.com/library/ios/qa/qa1747/_index.html
Yes, NSLog outputs on the device. You can see it's outputs with your device connected to your Mac and using Xcode Organizer tool.
If you use Testflight SDK, you can capture all logs with their Remote Logging feature.
I know this is an old thread but you can also have access to the device logs going to:
Settings -> Privacy -> Analytics -> Data
Hope this help
Regards
I think in Xcode 9.3 the device log screen has been moved to a new location.Kindly refer the following link.
Get device logs at runtime in Xcode

Resources