Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black Screen. No Camera Output. :( #1

Closed
vanvoorden opened this issue Apr 28, 2022 · 5 comments
Closed

Black Screen. No Camera Output. :( #1

vanvoorden opened this issue Apr 28, 2022 · 5 comments

Comments

@vanvoorden
Copy link
Owner

https://developer.apple.com/forums/thread/703735

@vanvoorden
Copy link
Owner Author

Building and running from Xcode 13.3.1 to iOS 15.4.1 results in a black screen with no camera input. The console errors look similar to the bug reported on the Apple Developer Forums.

@vanvoorden
Copy link
Owner Author

https://developer.apple.com/forums/thread/703735?answerId=711909022#711909022

There exist multiple hacky ways to fix this bug using Private (Apple) APIs. This one isn't super difficult to patch. I've confirmed this fixes the bug from Xcode 13.3.1 to iOS 15.4.1.

@vanvoorden
Copy link
Owner Author

diff --git a/SwizzledDecoder.m b/SwizzledDecoder.m
new file mode 100644
index 0000000..2af4106
--- /dev/null
+++ b/SwizzledDecoder.m
@@ -0,0 +1,60 @@
+//
+//  SwizzledDecoder.m
+//
+//  Copyright © 2021 North Bronson Software
+//
+//  This Item is protected by copyright and/or related rights. You are free to use this Item in any way that is permitted by the copyright and related rights legislation that applies to your use. In addition, no permission is required from the rights-holder(s) for scholarly, educational, or non-commercial uses. For other uses, you need to obtain permission from the rights-holder(s).
+//
+//  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#import <Foundation/Foundation.h>
+
+#import <objc/runtime.h>
+
+@interface SwizzledDecoder : NSObject
+
+- (void)__validateAllowedClass:(Class)arg1 forKey:(id)arg2 allowingInvocations:(bool)arg3;
+
+@end
+
+@implementation SwizzledDecoder
+
++ (void)load {
+  //  https://nshipster.com/method-swizzling/
+  
+  static dispatch_once_t onceToken;
+  dispatch_once(&onceToken, ^{
+    Class originalClass = NSClassFromString(@"NSXPCDecoder");
+    Class swizzledClass = NSClassFromString(@"SwizzledDecoder");
+    
+    SEL originalSelector = @selector(_validateAllowedClass:forKey:allowingInvocations:);
+    SEL swizzledSelector = @selector(__validateAllowedClass:forKey:allowingInvocations:);
+    
+    Method originalMethod = class_getInstanceMethod(originalClass, originalSelector);
+    Method swizzledMethod = class_getInstanceMethod(swizzledClass, swizzledSelector);
+    
+    IMP originalImp = method_getImplementation(originalMethod);
+    IMP swizzledImp = method_getImplementation(swizzledMethod);
+    
+    class_replaceMethod(originalClass,
+                        swizzledSelector,
+                        originalImp,
+                        method_getTypeEncoding(originalMethod));
+    class_replaceMethod(originalClass,
+                        originalSelector,
+                        swizzledImp,
+                        method_getTypeEncoding(swizzledMethod));
+  });
+}
+
+- (void)__validateAllowedClass:(Class)arg1 forKey:(id)arg2 allowingInvocations:(bool)arg3 {
+  if ([arg2 isEqualToString: @"collaborationData"]) {
+    return;
+  }
+  return [self __validateAllowedClass: arg1 forKey: arg2 allowingInvocations: arg3];
+}
+
+@end

Here is a diff to git apply to any repo that needs to fix around this issue on 15.4.x.

@vanvoorden
Copy link
Owner Author

It looks like Apple resolved the issue in iOS 15.5 (19F77).

@vanvoorden vanvoorden closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant