0

我在锁屏上有一个按钮可以在触摸时显示警报,我只是在玩这个东西并尝试这样做,但是当我触摸按钮时它会崩溃并重新进入安全模式。我在我的 iPhone 中使用 theos 运行它。这是我的代码:

#import <UIKit/UIKit.h>


@interface SBAwayView : UIView

@end


@interface SBAwayController

UIButton *myButton;
-(void)unlockWithSound : (BOOL)sound;

@end



%hook SBAwayController

-(id)lock{

SBAwayView *v = MSHookIvar<id>(self, "_awayView");

myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(21, 80, 100, 35);
[myButton setTitle:@"My Button" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(myButtonPressed)     forControlEvents:UIControlEventTouchUpInside];

[v addSubview:myButton];

%orig;
}

-(void)myButtonPressed{

UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Title of Alert"  message:@"Message of Alert" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK",  nil];
[theAlert show];
[theAlert release];

}


%end
4

2 回答 2

0

You needed %new(v@:) before your void;

%new(v@:)
-(void)myButtonPressed{

UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Title of Alert"  message:@"Message of Alert" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK",  nil];
[theAlert show];
[theAlert release];

}
于 2012-09-17T02:44:48.723 回答
0

首先尝试调试并查看函数是否被调用。

然后它也崩溃然后尝试使用自动释放

UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Title of Alert" message:@"Message of Alert" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK",  nil] autorelease] ;
[theAlert show];
于 2012-09-03T18:47:15.223 回答