调用系统相册UIImagePickerController白屏的问题

 

这是模拟器的打印日志

2020-12-28 20:23:42.699885+0800 [51686:3039686] Unable to setup extension context - error: Couldn’t communicate with a helper application.
2020-12-28 20:23:42.700117+0800 [51686:3040341] [default] Async Begin using error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.xxx.apple-extension-service was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.xxx.apple-extension-service was invalidated.}
2020-12-28 20:23:42.700402+0800 [51686:3039451] UIImagePickerController UIViewController create error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named xxx.apple-extension-service was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.xxx.apple-extension-service was invalidated.}

下面是真机报错日志
2020-12-29 09:31:28.501138+0800 [2572:223940] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service
2020-12-29 09:31:28.536772+0800 [2572:224163] Unable to setup extension context - error: 无法与帮助程序通信。
2020-12-29 09:31:28.537037+0800 [2572:223940] UIImagePickerController UIViewController create error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named nnn.apple-extension-service was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named nnn.apple-extension-service was invalidated.}
<2020-12-29 01:31:31 +0000UIViewController+DUBUG.m:(29)>--[UIViewController(DUBUG) logViewWillAppear:]-UIImagePickerController will appear-

<2020-12-29 01:31:31 +0000UIViewController+DUBUG.m:(29)>--[UIViewController(DUBUG) logViewWillAppear:]-_UIImagePickerPlaceholderViewController will appear-

2020-12-29 09:31:31.701503+0800 [2572:223940] [mPaaSLog] AutoTracker : Ignore vc track, vcClass = UIImagePickerController
2020-12-29 09:31:31.701664+0800 [2572:223940] [mPaaSLog] AutoTracker : didAppear viewController ignored,vcClass = UIImagePickerController
2020-12-29 09:31:33.497768+0800 [2572:224163] [lifecycle] [u BE90D2CC-F949-4FF3-ABCA-1FF164AD90A7:m (null)] [com.apple.mobileslideshow.photo-picker(1.0)] Connection to plugin interrupted while in use.
2020-12-29 09:31:33.498193+0800 [2572:224148] [lifecycle] [u BE90D2CC-F949-4FF3-ABCA-1FF164AD90A7:m (null)] [com.apple.mobileslideshow.photo-picker(1.0)] Connection to plugin invalidated while in use.
 

问题出在hook bundleid。

因为有些系统组件也会调用到这个方法但值有区别。

因此在- (NSDictionary*)infoDictionary方法和- (NSString *)bundleIdentifier中对下面几个需要特殊处理

1.@"com.apple.CoreGlyphs"

2.@"com.apple.uikit.BoundingPathData"

3.@"com.apple.AGXMetalA11"

4.@"com.apple.mobileslideshow.photo-picker"

5.@"com.apple.uikit.Artwork"

6.nil

代码如何编写呢

直接将这两个文件拖入工程

//
//  NSBundle+YYYY.h


#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSBundle (YYYY)

@end

NS_ASSUME_NONNULL_END


//  NSBundle+YYYY.m

#import "NSBundle+YYYY.h"
#import <objc/runtime.h>
#define openHook  0

@implementation NSBundle (YYYY)

+(void)load{
    Method originalMethod = class_getInstanceMethod([NSBundle class], @selector(bundleIdentifierS));
    Method swizzledMethod = class_getInstanceMethod([NSBundle class], @selector(bundleIdentifier));
    method_exchangeImplementations(originalMethod, swizzledMethod);
    
    {
        Method originalMethod = class_getInstanceMethod([NSBundle class], @selector(infoDictionary));
        Method swizzledMethod = class_getInstanceMethod([NSBundle class], @selector(infoDictionarySS));
        method_exchangeImplementations(originalMethod, swizzledMethod);
         
    }
}
- (NSString *)bundleIdentifierS{
    
    NSMutableDictionary*threadDict =  [[NSThread mainThread] threadDictionary];
    
    NSString *bundleIdentifierS = [self bundleIdentifierS];
    if([bundleIdentifierS isEqualToString:@"正式的"]||
       [bundleIdentifierS isEqualToString:@"com.apple.CoreGlyphs"]||
       [bundleIdentifierS isEqualToString:@"com.apple.uikit.BoundingPathData"]||
       [bundleIdentifierS isEqualToString:@"com.apple.AGXMetalA11"]||
       [bundleIdentifierS  isEqualToString:@"com.apple.mobileslideshow.photo-picker"]||
       [bundleIdentifierS  isEqualToString:@"com.apple.uikit.Artwork"]){
        
        return bundleIdentifierS;
    }
   
    if (([self bundleIdentifierS].length > 0) && ([[threadDict objectForKey:@"useHookBundleid"] boolValue] == YES) && openHook == 1) {
        return @"正式的";
    }else{
        return [self bundleIdentifierS];
    }
    

}
- (NSDictionary*)infoDictionarySS{
    
    NSMutableDictionary *dicc = [self infoDictionarySS].mutableCopy;
    
    NSMutableDictionary*threadDict =  [[NSThread mainThread] threadDictionary];
    
    if ([dicc[@"CFBundleIdentifier"]isEqualToString:@"正式的"] ||
        [dicc[@"CFBundleIdentifier"]isEqualToString:@"com.apple.CoreGlyphs"] ||
        [dicc[@"CFBundleIdentifier"]isEqualToString:@"com.apple.uikit.BoundingPathData"]
        ||[dicc[@"CFBundleIdentifier"]isEqualToString:@"com.apple.AGXMetalA11"]||
        [dicc[@"CFBundleIdentifier"]isEqualToString:@"com.apple.mobileslideshow.photo-picker"]|| [dicc[@"CFBundleIdentifier"]isEqualToString:@"com.apple.uikit.Artwork"]) {
        
    }else{
        
        if ([dicc allKeys].count > 0) {
            if ([[threadDict objectForKey:@"useHookBundleid"] boolValue] == YES && openHook == 1) {
               
                [dicc setObject:@"正式的" forKey:@"CFBundleIdentifier"];

            }
        }
        

    }
    return dicc;
}
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值