2016-11-04 86 views
0

我有一個測試應用程序(它什麼都不做,因爲我用它來測試一個bug),其中包括我構建的3個框架。框架使用複製文件階段複製到應用程序的Frameworks目錄中。我有以下應用程序的委託代碼:iOS:objc_copyClassNamesForImage不能在設備上工作

#import "AppDelegate.h" 
@import ObjectiveC; 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    [[NSBundle allFrameworks] enumerateObjectsUsingBlock:^(NSBundle *framework, NSUInteger idx, BOOL *stop) { 
     unsigned int count = 0; 
     __unused const char** classes = objc_copyClassNamesForImage([[framework executablePath] UTF8String], &count); 
     NSRange inFramework = [framework.executablePath rangeOfString:@".app/Frameworks"]; 
     if (inFramework.length > 0) { 
      NSLog(@"Framework %@, classes: %i", framework.executablePath.lastPathComponent, count); 
     } 
    }]; 
    return YES; 
} 

@end

打印出從框架目錄的框架,幷包含在每個類的數量。

當我運行在模擬器中,我得到的結果如下這段代碼:當我在設備上運行它

2016-11-04 12:02:17.682 RuntimeTest[54326:623229] Framework PEGKit, classes: 24 
2016-11-04 12:02:17.705 RuntimeTest[54326:623229] Framework Alchemic, classes: 57 
2016-11-04 12:02:17.707 RuntimeTest[54326:623229] Framework StoryTeller, classes: 10 

但是我得到:

2016-11-04 12:07:04.215417 RuntimeTest[1035:365233] Framework PEGKit, classes: 0 
2016-11-04 12:07:04.224495 RuntimeTest[1035:365233] Framework Alchemic, classes: 0 
2016-11-04 12:07:04.254946 RuntimeTest[1035:365233] Framework StoryTeller, classes: 0 

的設備是iPhone 7 iOS 10.1。我很確定這段代碼在過去有效,看起來objc_copyClassNamesForImage在某種程度上被破壞了。

我的工作理論是,這可能是一些10.1的錯誤。或者可能是在構建屬性中設置/未設置的內容。

在任何人能夠證實這一點?或者有什麼想法可能是錯誤的?

回答

0

在設備上,您應該使用/private前綴框架圖像的路徑。如果你問一個包的路徑,你會看到它有/private前綴。這就是我找到解決方法的方法。

相關問題