سؤال

Basically, I'm trying to display an application using the private API SBAppContextHostManager of SpringBoard. So far, I have this code:

SBAppContextHostManager *app = [[objc_getClass("SBAppContextHostManager") alloc] init];

[app setAppBundleID:@"com.apple.springboard"]; // just as an example

[app enableHostingForRequester:@"uniqueID" priority:1];

[app orderRequesterFront:@"uniqueID"];

SBHostWrapperView *view = [app hostViewForRequester:@"uniqueID"];

and after which I call

UIGraphicsBeginImageContextWithOptions([UIScreen mainScreen].bounds.size, YES, [UIScreen mainScreen].scale);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(c, YES);
[view.layer renderInContext:c];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

to grab a UIImage of the view containing the application. However, the output of this UIImage is completely blank, which leads me to think that my calls to SBAppContextManager are incorrect, thus leading to a blank SBHostWrapperView. Therefore, how should I display an application in this way?

هل كانت مفيدة؟

المحلول

If you are trying to get a preview of the application, rendering an SBHostWrapperView won't work. You see, SBHostWrapperViews don't copy the application's render output, it simply provides a different location on the screen for the app to render to.

Instead, you can use - (SBFullscreenZoomView*)systemGestureSnapshotWithIOSurfaceSnapshotOfApp:(SBApplication*)arg1 includeStatusBar:(BOOL)arg2; in the SBUIController class.

That method returns an SBFullscreenZoomView, a subclass of UIView, with a snapshot of the app provided in arg1. You can use the second snippet of code you provided to get a UIImage of the SBFullscreenZoomView. That should do what you are asking, providing you with a screenshot of only a specific application.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top