下在iOS的10蘋果已經做出了改變那的NSLog()輸出不是在分佈式應用程序(企業應用程序商店)發出的。在分佈式應用程序沒有的NSLog輸出的iOS 10
需要注意的是在Xcode,的NSLog()運行時工作正常。
有沒有辦法迫使所有的應用程序(在beta測試階段非常有用)的調試?
一些線索出現在這裏:NSLog on devices in iOS 10/Xcode 8 seems to truncate? Why?
但是,我們可以對此有一個明確的實施?
下在iOS的10蘋果已經做出了改變那的NSLog()輸出不是在分佈式應用程序(企業應用程序商店)發出的。在分佈式應用程序沒有的NSLog輸出的iOS 10
需要注意的是在Xcode,的NSLog()運行時工作正常。
有沒有辦法迫使所有的應用程序(在beta測試階段非常有用)的調試?
一些線索出現在這裏:NSLog on devices in iOS 10/Xcode 8 seems to truncate? Why?
但是,我們可以對此有一個明確的實施?
我們的解決方案取決於兩個問題:
我們會找到答案的問題[1]在編譯時。對於[2]我們必須在運行時進行測試。
下面是執行:
mylog.h
//only used to force its +load() on app initialization
@interface MyLog:NSObject
@end
#if !__has_builtin(__builtin_os_log_format)
//pre Xcode 8. use NSLog
#else
//we need this include:
#import <os/log.h>
#endif
void myLog(NSString *format, ...);
#ifdef DEBUG
#define NSLog(f, ...) myLog(f, ## __VA_ARGS__)
#else
#define NSLog(f, ...) (void)0
#endif
mylog.m
@implementation MyLog
BOOL g_useNewLogger = NO;
+(void)load
{
NSOperatingSystemVersion os_ver = [[NSProcessInfo processInfo] operatingSystemVersion];
if (os_ver.majorVersion >= 10) {
g_useNewLogger = YES;
}
NSLog(@"Use new logger: %@", g_useNewLogger? @"YES":@"NO");
}
@end
void myLog(NSString *format, ...)
{
va_list args;
va_start(args, format);
#if !__has_builtin(__builtin_os_log_format)
//pre Xcode 8. use NSLog
NSLogv(format, args);
#else
//Xcode 8 and up
if (g_useNewLogger) { // >= iOS 10
NSString *nsstr = [[NSString alloc] initWithFormat:format arguments:args];
os_log(OS_LOG_DEFAULT, "%{public}s", [nsstr cStringUsingEncoding:NSUTF8StringEncoding]);
} else { // < iOS 10
NSLogv(format, args);
}
#endif
va_end(args);
}
如果你想有一個插入式解決方案,以獲得你的應用程序日誌,我建議你看看我們的工具已經創造出來了。它被稱爲Bugfender,它所做的是將所有應用程序日誌發送到我們的服務器,以便您可以在我們的網站上查看它們。
這一邊做beta測試是非常有用的,因爲你的用戶可以測試應用程序,如果他們發現一個問題,你會得到他們的應用程序所做的一切信息。