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?
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.
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.
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
I have an iPod touch running iOS 4.2.1, and a simulator running iOS 4.2. In the simulator, my code works just fine, but on the device, it crashes.
The code in question is:
FILE *file = fopen([[#"niplot/" stringByAppendingString:text_field.text] fileSystemRepresentation], "w");
...
fprintf(file, "%s", [print_str UTF8String]); //crash occurs here, EXC BAD ACCESS
...
fclose(file);
Could it have something to do with the file or folder not existing? The simulator created them for me in this case. I'd try to create the files and folders manually on the device, but I'm not sure how. Also, I've tried the file names with and without a .txt extension.
Here's some examples of file save/load/delete.