如何hook category方法

category 定义如下
@interface UIDevice (Hardware)

  • (id)platformCode;
  • (id)platformString;
    @end

写成:
%hook UIDevice

  • (id)platformCode { %log; id r = %orig; NSLog(@" = %@", r); return r; }
  • (id)platformString { %log; id r = %orig; NSLog(@" = %@", r); return r; }
    %end

Log提示如下:
Sep 6 14:34:17 liangyongs-iPhone MobileSafari[3045] : MS:warning: message not found [UIDevice platformCode]
Sep 6 14:34:17 liangyongs-iPhone MobileSafari[3045] : MS:warning: message not found [UIDevice platformString]

写成
%hook UIDevice (Hardware)

  • (id)platformCode { %log; id r = %orig; NSLog(@" = %@", r); return r; }
  • (id)platformString { %log; id r = %orig; NSLog(@" = %@", r); return r; }
    %end
    编译出错