Question

Hi guys I have been trying to develop a cydia that will animate a image inside a UIImageView, and I think that my code is all good but for some reason the app just crashes every time that perform the task. I have read that this could be the cause of loading too many images at once but I'm only trying to load 2 small png images so i don't think that could be the cause. Please let me know what you think!

%hook UISaveToCameraRollActivity
-(void)performActivity {
%orig;
NSBundle *bundle = [[NSBundle alloc] initWithPath:kBundlePath];
NSString *imagePath = [bundle pathForResource:@"hand" ofType:@"png"];
NSString *imagePath1 = [bundle pathForResource:@"floppy" ofType:@"png"];
UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]
bounds]];
statusWindow.windowLevel = UIWindowLevelStatusBar;
statusWindow.hidden = NO;
statusWindow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
UIImageView *pic = [[UIImageView alloc] initWithFrame:CGRectMake (0, 0, 69, 69)];
pic.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"hand.png"],
[UIImage imageNamed:@"floppy.png"], nil];
pic.animationDuration = 1.0f;
[pic startAnimating];
pic.animationRepeatCount = 0;
[pic release];
pic.center = statusWindow.center;
pic.image = [UIImage imageWithContentsOfFile:imagePath];
pic.image = [UIImage imageWithContentsOfFile:imagePath1];
[statusWindow addSubview:pic];
[statusWindow makeKeyAndVisible];

}
%end
Was it helpful?

Solution

Move:

[pic release];

to the end of your method. You should NEVER interact with an object once you release it, this is almost a guaranteed way to crash your app.

If you do not want to be bothered with manually managing memory, you should give ARC a try:

https://developer.apple.com/library/ios/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top