2016-12-20 66 views

回答

0

我們可以通過下面的代碼

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
NSDictionary *settings = [defaults objectForKey:@"RCTDevMenu"]; 
NSMutableDictionary *newSettings = [NSMutableDictionary dictionaryWithDictionary:settings]; 
newSettings[@"RCTPerfMonitorKey"] = @1; 
[defaults setObject:newSettings forKey:@"RCTDevMenu"]; 
[defaults synchronize]; 

編程啓用性能監視器更新後的設置,它會從RCTDevMenu觸發通知'settingsDidChange'。

我們可以在性能監視器啓用後獲得FPS。這將增加性能監視器窗口(應該是最後一個對象)

UIView *performanceMonitorView = self.window.subviews.lastObject; 
for (id view in performanceMonitorView.subviews) { 
    if ([view isKindOfClass:[RCTFPSGraph class]]){ 
    RCTFPSGraph *fpsGraph = (RCTFPSGraph *)view; 
    NSLog(@"FPS Graph minFPS: %zd maxFPS: %zd fps: %zd", fpsGraph.minFPS, fpsGraph.maxFPS, fpsGraph.FPS); 
    } 
} 

然後我們可以遍歷性能監視器子視圖並保存RCTFPSGraph實例來獲得FPS。