我在锁屏中有一个按钮,当触摸时显示警报,我只是在玩这个东西并尝试这样做,但是当我触摸按钮时它会崩溃并重新进入安全模式。我在我的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
答案 0 :(得分:0)
首先尝试调试并查看是否调用函数。
然后它崩溃然后尝试使用autorelease
UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Title of Alert" message:@"Message of Alert" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil] autorelease] ;
[theAlert show];
答案 1 :(得分:0)
你的虚空之前需要%new(v @ :);
%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];
}