这是模拟器的打印日志
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