How to hook to a function to iOS alarms? - objective-c

I'm trying to use Theos in order to hook up and capture the names of the alarms that have been stopped.
I have done this:
// Logos by Dustin Howett
// See http://iphonedevwiki.net/index.php/Logos
//#import <SpringBoard/SpringBoard.h>
#import <MobileTimer/AlarmManager.h>
//#import <SpringBoard/SBApplicationIcon.h>
#import <UIKit/UIKit.h>
//#import <SpringBoard/SBRemoteNotificationEnableSystemwideAlert.h>
%hook AlarmManager
- (void)handleAlarm:(id)arg1 stoppedUsingSong:(id)arg2 {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ALARM!!!!" message:#"HELLO!!!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
%orig(arg1,arg2);
}
%end
The problem is that I never see the alertbox. Do you have any ideas why this is?

After [alert show]; put [alert release];
This:
%hook AlarmManager
- (void)handleAlarm:(id)arg1 stoppedUsingSong:(id)arg2 {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ALARM!!!!" message:#"HELLO!!!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
%orig(arg1,arg2);
}
%end

Related

Passing variables inside Appdelegate

When I use a variable inside AppDelegate and then I use it inside a function the variable doesn't change its value!
Any help? I use objective c
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// Show alert for push notifications recevied while the
// app is running
NSString *message = [[userInfo objectForKey:#"aps"]
objectForKey:#"alert"];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#""
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
How can I get message outside of this function?
You can make a class variable :
NSString *mesage;//You can use this variable anywhere in AppDelegate
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// Show alert for push notifications recevied while the
// app is running
message = [[userInfo objectForKey:#"aps"]
objectForKey:#"alert"];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#""
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];

Objective C dismissViewControllerAnimated move last view down

I have two ViewController
VC1 adding VC2 as an subview to itselfe.
VC2 has a UIButton, which is calling the follow Code:
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:[NSString stringWithFormat:#"BlaBla."]];
NSArray *toRecipients = [NSArray arrayWithObjects:#"blabla#gmail.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = [NSString stringWithFormat:#"Testtext1"];
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Fehler" message:#"Ihr Gerät unterstützt die gewünschte Funktion nicht" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}
After the Mail is done it calls the following:
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
switch (result)
{
case MFMailComposeResultCancelled:
{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hinweis"
message:#"Vorgang abgebrochen, es wurde keine E-Mail versendet."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
[alert show];
}
break;
case MFMailComposeResultSaved:
{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hinweis"
message:#"Ihre E-Mail wurde gespeichert."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
[alert show];
}
break;
case MFMailComposeResultSent:
{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hinweis"
message:#"Ihre E-Mail wird versendet."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
[alert show];
}
break;
case MFMailComposeResultFailed:
{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hinweis"
message:#"Vorgang abgebrochen, die E-Mail konnte nicht gesendet werden."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
[alert show];
}
break;
default:
{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hinweis"
message:#"E-Mail wurde nicht gesendet."
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles: nil];
[alert show];
}
break;
}
[self dismissViewControllerAnimated:YES completion:nil];}
All works fine, but all UIButtons etc in VC2 are now moved, I guess, 20 pixels down.
I cant Imagin why, I guess the problem is I adding a ViewController as Subview to an other ViewController and calling there the methode. But I cant imagin how to solve the issue.
I had similar problem but parent view was moved 20 px up.
Solution was based on changing "Wants full screen". I had to set this values to YES but not to all child view controllers.

clickedButtonAtIndex: not working

Hi guys i have this i IBAction linked to a button:
- (IBAction)showCurl:(id)sender {
alert1 = [[UIAlertView alloc]initWithTitle:#"Loading" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert1 show];
}
and a clickedButtonIndex to auto run but somehow it doesn't load SecondViewController:
#pragma mark UIAlertView
- (void)alertView:(UIAlertView *)alert1 clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 0){
SecondViewController *sampleView = [[SecondController alloc] init];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
}
else{
// Cancel prompt
}
}
Am i missing something here?
If you don’t give the alert view some button titles, there won’t be any buttons to tap on and that delegate method won’t get called.
- (IBAction)showCurl:(id)sender {
alert1 = [[UIAlertView alloc] initWithTitle:#"Loading" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert1 show];
}
Your code doesn't show a button
alert1 = [[UIAlertView alloc]initWithTitle:#"Loading" message:nil delegate:self cancelButtonTitle:**nil** otherButtonTitles:**nil**];
You pass nil as cancelButtonTitle AND nil as otherbuttonTitles, you should at least have one button title set.

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.

otherButtonTitles in UIAlertView

I was just curious about how can i attach some different task to the otherButtonTitle of UIAlertView.
The cancel button automatically take you out of the application but if i want to attach a different task with the otherButtonTitle ,what should i do?
Thanks,
UIAlertView delegate "didDismissWithButtonIndex" get called every time u click any button.
Try this:
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Message"
message:messageString
delegate:self
cancelButtonTitle:#"Back"
otherButtonTitles:#"Reply",#"Delete",nil];
[alert show];
[alert release];
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
NSLog(#"Reply");
UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:#"Button Clicked" message:#"U clicked Reply " delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[myalert show];
[myalert release];
}
if (buttonIndex == 2)
{
NSLog(#"Delete");
UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:#"Button Clicked" message:#"U clicked Delete " delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[myalert show];
[myalert release];
}
}