1

Objective-C で作成されたアプリケーションでいくつかのメソッドをスウィズルしようとしています。次のエラーが表示されます。

Symbol not found: _OBJC_CLASS_$_IASAvatarViewController

Hopper で実行可能ファイルを開くと、代わりにすべてのクラスに接頭辞が付いていることがわかりますobjc_class_。したがって、私がスウィズルしようとしているメソッドのクラス名はobjc_class_IASAvatarViewController. まず、クラス識別子がどのようにそのようになったのか知りたくてたまりません (ある種の名前マングリング?)。次に、dylib が正しい識別子を参照できるかどうかを知りたいです。

DylibTest.h:

#import <UIKit/UIKit.h>
#import <objc/runtime.h>

@interface IASBaseViewController : UIViewController

@end

@interface IASAvatarViewController : IASBaseViewController

@end

@interface IASAvatarViewController (Swizzle)

@end

DylibTest.m

#import "DylibTest.h"
#import <dlfcn.h>

@implementation IASAvatarViewController (Swizzle)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];

        SEL originalSelector = @selector(viewDidLoad);
        SEL swizzledSelector = @selector(xxx_viewDidLoad);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

        BOOL didAddMethod =
        class_addMethod(class,
                    originalSelector,
                    method_getImplementation(swizzledMethod),
                    method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                            swizzledSelector,
                            method_getImplementation(originalMethod),
                            method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
 }


 - (void)xxx_viewDidLoad {
    [[[UIAlertView alloc] initWithTitle:@"Swizzled method" message:@"Ya swizzle" delegate:nil cancelButtonTitle:@"Yeah. Okay" otherButtonTitles:nil] show];

    [self xxx_viewDidLoad];
 }

 @end

そして、Objective-C クラスを含むホッパーのスクリーン ショット: ホッパーのスクリーンショット

編集:画像を直接投稿するのに十分な評判を得ました.

Edit2: class-dumpファイルの: http://pastebin.com/DcUD5AL5

4

0 に答える 0