【问题标题】:How is this working? - Jailbreak Tweak这是如何工作的? - 越狱调整
【发布时间】:2014-04-25 01:18:49
【问题描述】:

我对越狱 iOS 调整开发非常陌生,并且有一个问题。每当从 Springboard 打开应用程序时,我都会按照教程进行提示。调整代码是:

#include <UIKit/UIKit.h>
@interface SBApplicationIcon
- (void)launchFromLocation:(int)arg;
- (id)displayName;
@end

%hook SBApplicationIcon

-(void)launchFromLocation:(int)location{

        NSString *appName = [self displayName];
        NSString *message = [NSString stringWithFormat:@"Application launched: %@", appName];
        UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:appName message:message delegate:nil cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
        [myAlert show];

    %orig;
}//end function

%end

这个调整代码工作得很好。我不明白这是如何工作的。查看SBApplicationIcon的头文件,没有-(void)launchFromLocation:(int)location;

这样的方法

经过一些研究,虽然我发现 SBIcon 类头有这个确切的函数定义。如果我将代码更改为:

#include <UIKit/UIKit.h>
@interface SBIcon
- (void)launchFromLocation:(int)arg;
- (id)displayName;
@end

%hook SBIcon

-(void)launchFromLocation:(int)location{

        NSString *appName = [self displayName];
        NSString *message = [NSString stringWithFormat:@"Application launched: %@", appName];
        UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:appName message:message delegate:nil cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
        [myAlert show];

    %orig;
}//end function

%end

警报视图不会出现,并且该函数永远不会被调用!我觉得这是一个愚蠢的问题,但我根本不明白这是如何工作的。有人可以向我解释一下吗?我正在使用 iOS7 标头和 iOS7 iPhone。

谢谢!

【问题讨论】:

  • 你错了。不是一个愚蠢的问题:)
  • 好问题。但是,我不知道您是否启用了 ARC,但如果您没有启用,请不要忘记 [myAlert release]; !

标签: ios ios7 hook jailbreak theos


【解决方案1】:

SBIcon 的 -launch 方法(至少从 iOS 5 开始,不知道之前的情况)一直存在,只是为了在子类中被覆盖,例如 SBLeafIcon,SBApplicationIcon 的超类。 iOS 7 中的 -launchFromLocation: 也是如此。因此,SBIcon 的实现永远不会被调用(如果它只是一个空方法,为什么要调用 super 呢?),所以如果你钩住 SBIcon,你的代码永远不会运行。

【讨论】:

  • 我相信launchFromLocation:实际上是在SBLeafIcon中实现的,它是SBIcon的子类,也是SBApplicationIcon的超类。
  • @Nate 很有可能——不完全确定。
  • @Nate 确实,您似乎是对的。谢谢。更新了我的答案。
猜你喜欢
  • 1970-01-01
  • 2023-04-02
  • 2014-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多