iOS: How to hook into MPMoviePlayerController? - objective-c

Okay so i am wanting to create a tweak that hooks into the MPMovieController.h file and changes the scaling button to another button. So firstly i checked i can hook into that class just for testing reason, so i hooked into the play function to see if when a video had began playing if i could show a UIAlertView. However I was unable to do so. Even though everything compiled fine and the DEB file was built successfully I still can not get this message to appear when the movie player is playing.
This is my Code:
Tweak.xm:
#import <UIKit/UIKit.h>
#interface MPMoviePlayerController
-(void)play;
#end
%hook MPMoviePlayerController
-(void)play
{
NSString *Title = [NSString stringWithFormat:#"Title", nil];
NSString *message = [NSString stringWithFormat:#"Message", nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:Title message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
%orig;
}
%end
Thanks. P.S. After Installing I have reset and re-sprung my iphone.

Related

How to deal with this NSString correctly with cocos2d?

I'm new with cocos2d so i've got a problem with my In-App Purchase Class Helper. I wrote game in Cocoa Touch and this class working perfectly, but i'm writing now the same game in Cocos2d and problem is with NSString.
Here are some snippets.
This method is called as first when i clicked some button. As you see completeIdentifier is simple string with bundleIdentifier and some string parameter. It's ok, in this place i can log this completeIdentifier.
- (void)prepareToPurchaseItemWithIdentifier:(NSString *)aIdentifier showAlertWithTitle:(NSString *)title description:(NSString *)description delegate:(id)aDelegate{
self.delegate = aDelegate;
identifier = aIdentifier;
completeIdentifier = [NSString stringWithFormat:#"%#.%#", [[NSBundle mainBundle] bundleIdentifier], aIdentifier];
askToPurchase = [[UIAlertView alloc] initWithTitle:title message:description delegate:self cancelButtonTitle:nil otherButtonTitles:#"Later", #"Yes", nil];
askToPurchase.delegate = self;
[askToPurchase show];
}
Next method is UIAlertViewDelegate method. Is called when i click YES on alertView from first method.
#pragma mark - UIAlertViewDelegate Methods
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(#"%#", completeIdentifier);
if (alertView == askToPurchase) {
NSLog(#"[TSIAPHelper] Clicked YES. Prepare...");
if ([SKPaymentQueue canMakePayments]) {
NSLog(#"[TSIAPHelper] Prepare to purchase [%#].",completeIdentifier);
SKProductsRequest *request =[[SKProductsRequest alloc] initWithProductIdentifiers:
[NSSet setWithObject:completeIdentifier]];
request.delegate = self;
[request start];
pleaseWait = [[UIAlertView alloc] initWithTitle:#"Please wait..." message:#"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[activity startAnimating];
[pleaseWait addSubview:activity];
activity.frame = CGRectMake(125, 50, 36, 36);
[pleaseWait show];
}
else {
NSLog(#"[TSIAPHelper] Purchase [FAILURE]. Prohibited by Parentar Control or something like that.");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Prohibited." message:#"Parental Control is enabled, cannot make a purchase. Turn off and try again." delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alert show];
}
}
}
The problem is: Whenever and anywhere i want to Log variable completeIdentifier i've got crash with selected line: 0x39e965d0: ldr r3, [r4, #8] but i don't know what's that mean. And this line is selected:
NSLog(#"%#", completeIdentifier);
How can i fix it? In Cocoa Touch is working perfectly. When i use cocos2d isn't.
I guess you aren't using ARC. In this case completeIdentifier will be autoreleased.
Cocos2d clears the autoreleasepool every frame, whereas in Cocoa this is not strictly defined but may still crash. You can fix this by retaining or copying the string.
completeIdentifier = [NSString stringWithFormat:#"%#.%#", [[NSBundle mainBundle] bundleIdentifier], aIdentifier];
completeIdenfitier = [completeIdentifier retain];

How do I send the iOS user an instant local notification?

I simply want a notification to pop up when the user presses a button. No servers or timers needed. All the tutorials I can find seem to involve one of these two.
Maybe something like this:
-(IBAction) buttonPressed: (UIButton *)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: [NSString stringWithFormat:#"You pressed button %#", sender.tag]
message: #"message"
delegate: self
cancelButtonTitle: #"Ok"
otherButtonTitles: nil]];
[alert show];
}
It would look something like this:
You can also customize the alert view a bit, so it could potentially have a textfield for text entry:
With UIAlertViews, you can also implement protocol methods like – alertView:clickedButtonAtIndex: and – alertView:willDismissWithButtonIndex:to perform different actions depending on which alert button they pressed.
Here's a good tutorial on UIAlertViews and implementing their protocol methods: http://mobile.tutsplus.com/tutorials/iphone/uialertview/.
If you don't want to use UIAlertViews and instead want a more customizable modal view, check out these two great libraries called UAModalPanel and MJPopupViewController. You can check out the links for images, demos, and more info on the two libraries, including links to their github pages where you can download them.
Hope this helps!
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelMessage];
[alertView show];
It is important to make sure the alert is shown on the main thread, where all the UI is handled. Otherwise you may get some weird errors and/or crashes. You can use GCD to dispatch to the main thread:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert Test"
message:#"This is an alert test."
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK",
nil];
dispatch_async(dispatch_get_main_queue(), ^{
[alert show];
});

Using an NSString as UIAlertView message:

I can't figure out why this won't work, I've tried it 100 ways. The AlertView shows up with a blank message. Here's my code:
eventChoiceNow = [[UIAlertView alloc] initWithTitle:#"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
timeTillRest is an NSString. and just before calling the alertview an NSLog(#"%#",timeTillRest); displays the string without trouble.
Why would you use an alertview as an instance variable? There's no need for that. It's just as easy as this:
UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:#"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[eventChoiceNow show];
[eventChoiceNow release];
This should work just fine. Testing using this code:
NSString *timeTillRest = #"Testing";
UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:#"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[eventChoiceNow show];
And it works fine. Also testing using:
#import "ViewController.h"
#interface ViewController ()
#property(nonatomic,strong) NSString *timeTillRest;
#end
#implementation ViewController
#synthesize timeTillRest;
- (void)viewDidLoad
{
[super viewDidLoad];
timeTillRest = #"Testing";
UIAlertView *eventChoiceNow = [[UIAlertView alloc] initWithTitle:#"Hurry Up!" message:timeTillRest delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[eventChoiceNow show];
// Do any additional setup after loading the view, typically from a nib.
}
And that works flawlessly too. Make sure you aren't setting that property to nil anywhere.

UIAlertView delegate methods don't response on iOS 5.1

I created an instance of UIAlertView with two buttons and in the interface file of my class(.h) I set the delegate too but still cant get any response when clicking the buttons. Here is my code:
//myClass.h
#interface MainMenu : UIViewController<UIAlertViewDelegate>
-(IBAction)secondAct:(id)sender;
And the implementation
-(IBAction)secondAct:(id)sender
alert = [[UIAlertView alloc] initWithTitle:#"Dear User"
message:#"Your Request Will be Sent To Security"
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[alert show];
[alert autorelease];
}
and the delegate method:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(#"UIAlertView delegate works");//this line too isnt displayed
NSString *title=[ alertView buttonTitleAtIndex:buttonIndex ];
if ([title isEqualToString:#"OK"]) {
NSLog(#"OK Pressed");
}//i want to create something like this
}
I did all of the code above but still can't take any action. Whichever of the buttons i click, it dissmisses the alert. What is wrong with this code can any one help?
ANSWER
Dear PeterG. commented to change delegete:nil with delegate:self and it works now.
Delegate should probably be set to self. If it generates an error post it here.
Also I do not think you should autorelease the alert ivar. Try to skip that line and see what happens?
Just give the delegate "self".
-(IBAction)secondAct:(id)sender
alert = [[UIAlertView alloc] initWithTitle:#"Dear User"
message:#"Your Request Will be Sent To Security"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[alert show];
}

Trying to Integrate Mail Into my app, getting 2 warnings

I'm trying to integrate sending mail into my app, but I end up with 2 warnings. I am using Obj-C, the Cocos2d Framework. This is my code.
-(void) mailTapped: (id) sender {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:#"", nil]];
[composer setSubject:#"Check Out This Awesome App!"];
[composer setMessageBody:#"I found this great game on the App Store! It's called Mole Attack. It's a side scroller with an epic story. You can check out some screenshots of the gameplay and download it here. Download link - " isHTML:NO]; //Include link and pics
[self presentModalViewController:composer animated:YES]; // <--- warning - GameOver (name of class) may not respond to '-presentModalViewController:animated:'
}
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES]; // <--- warning - GameOver may not respond to '-dismissModalViewControllerAnimated:YES'
if (result == MFMailComposeResultFailed) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failed" message:#"The email was not sent. You must be in wifi or 3G range. Try again later." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Thanks in advance!
Are you sure your GameOver class is inheriting from UIViewController? That's the class that defines the two methods that you're getting warnings about.