[英]Xamarin forms iOS debug on iPhone from windows without cable
[英]iOS app debug without cable
是否可以登錄到 iPhone 上的文件(或以某種方式獲取控制台輸出)以便稍后讀取,或者直接從手機讀取?
我需要調試一個使用有線連接附件設備的應用程序,因此它不能同時連接到 XCode。
您可以使用PonyDebugger 。
我經常使用它來調試網絡和 CoreData 資源,但它也允許使用 PDLog 登錄到控制台。
PonyDebugger 是一個遠程調試工具集。 它是一個客戶端庫和網關服務器的組合,它使用瀏覽器上的 Chrome 開發者工具來調試應用程序的網絡流量和托管對象上下文。
一些建議:
[debugger connectToURL:[NSURL URLWithString:@"ws://192.168.0.12:9000/device"]];
很遺憾蘋果沒有為Xcode提供WiFi調試,但是對於你的問題,答案是肯定的,你絕對可以將NSLog重定向到一個日志文件,你可以試試這個方法:
// this will redirect all NSLog in your project, add it to PCH file.
#define NSLog(args...) writeLog(__PRETTY_FUNCTION__, __LINE__, args)
void writeLog(const char *function, int lineNumber, NSString *format, ...) {
// basic log content.
va_list ap;
va_start (ap, format);
NSString *msg = [[NSString alloc] initWithFormat:format arguments:ap];
va_end (ap);
// add function name, and line number.
NSString *log = [NSString stringWithFormat:@"%s line %d $ %@", function, lineNumber, msg];
// add your own code to write `log` into a text file.
....
}
注意:如果您使用的一些庫也將日志寫入控制台,則此宏不會將這些日志重定向到您的日志文件,它只會在您自己的源文件中與NSLog
一起使用。
據我所知,這是不可能的。
您最終可以使用免費且優秀的解決方案,例如bugfender ,它允許您遠程獲取 NSLog 記錄的數據。 這可以幫助你。
Kevin Xi 的做法是可以的。 您還可以使用 AppDelegate 的 didFinishLaunchingWithOptions 方法中的以下代碼將 NSLog 輸出重定向到文件:
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [allPaths objectAtIndex:0];
NSString *pathForLog = [documentsDirectory stringByAppendingPathComponent:@"log.txt"];
freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+", stderr);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.