美文网首页
iOS本地埋点记录

iOS本地埋点记录

作者: 香烟不灭 | 来源:发表于2024-07-09 15:40 被阅读0次
     dispatch_async(dispatch_get_main_queue(), ^{
                NSString *log = [NSString stringWithFormat:@"发送==%@==%@",[AppUtils timeWithStiring:[NSDate date] Withformat:@"yyyy-MM-dd HH:mm:ss"],urlStr];
                [self logstrSet:log];
                [[AppUtils getCurrentVC].view makeToast:log duration:1.5 position:CSToastPositionBottom];
            });
    
    
    
    -(void)logstrSet:(NSString*)logText{
        
        // 获取 Documents 目录路径
        NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    
        // 创建日志文件路径
        NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:@"myapp.log"];
    
        // 打开文件,并追加写入日志信息
        NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:logFilePath];
        if (fileHandle == nil) {
            [[NSFileManager defaultManager] createFileAtPath:logFilePath contents:nil attributes:nil];
            fileHandle = [NSFileHandle fileHandleForWritingAtPath:logFilePath];
        }
    
        if (fileHandle != nil) {
            // 将日志信息写入文件
            NSString *logMessage = [NSString stringWithFormat:@"\n%@========%@", [NSDate date], logText];
            [fileHandle seekToEndOfFile];
            [fileHandle writeData:[logMessage dataUsingEncoding:NSUTF8StringEncoding]];
            [fileHandle closeFile];
        }
     
    }
    

    自己写个埋点,记录下。

    相关文章

      网友评论

          本文标题:iOS本地埋点记录

          本文链接:https://www.haomeiwen.com/subject/lzodcjtx.html