[iOS][objective-c] when freopen is called, can't pass the next line of code
-
wrote on 24 Jun 2021, 03:24 last edited by
Hello all.
I have a problem in qt-iOS environment.
First, my environnment is below.
- XCode Version 12.5
- QT 5.14.2
- Fixed : https://codereview.qt-project.org/c/qt/qtbase/+/314522/1/mkspecs/features/toolchain.prf
- I didn't use QT, I used [projectName].xcodeproj generated as a result of QT Build
- iOS Device 14.6
I want to save the log output from my app as a file on the device.
I've found a very simple way to use it in an iOS environment.The way I found is to redirect the Console Log and save it to a file.
When I used this solution, I've actually seen it work and create a Log File.
However, this solution works and doesn't work for some unknown reason. (intermittently does not work)Is this a bug in QT? Or is there a problem using my solution?
@implementation QIOSApplicationDelegate (QTAppDelegate) - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"[AppDelegate_Log] didFinishLaunchingWithOptions"); NSDateFormatter *currrentSystemTime = [[NSDateFormatter alloc] init]; [currrentSystemTime setDateFormat:@"ddhhmm"]; NSString *logFileName = @"logcat_"; NSString *logStartTime = [currrentSystemTime stringFromDate:[NSDate date]]; logFileName = [logFileName stringByAppendingString:logStartTime]; logFileName = [logFileName stringByAppendingString:@".log"]; NSLog(@"[AppDelegate_Log] logFile Name : %@", logFileName); #if TARGET_IPHONE_SIMULATOR == 0 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *logPath = [documentsDirectory stringByAppendingPathComponent:logFileName]; NSLog(@"[AppDelegate_Log] logFile Path : %@", logPath); NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *fileList = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:NULL]; NSLog(@"[AppDelegate_Log] fileList!!!! : %@", fileList); freopen([logPath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr); #endif NSLog(@"[AppDelegate_Log] Exit"); return YES; } @end
1/1