Using an NSString as UIAlertView message: - objective-c

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.

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];

UIAlertView On Button Click

Yes, I've already Googled this question and I've used the exact code, but that's still not working.
Here is my current Objective-C code:
- (IBAction)btnTemp:(id)sender
{
if (_deepSwitch.on == TRUE)
{
[self TempCleaner];
_progress.progress += 1;
}
UIAlertView *cleaned = [[UIAlertView alloc] initWithTitle:#"Done!" message:#"Your device is now clean. Restarting SpringBoard." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[cleaned show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == [alertView cancelButtonIndex]) {
NSLog(#"clicked");
}
}
Why isn't this working? I've tried buttonIndex 0, and cancel button!
Set the alert view's delegate to self
UIAlertView *cleaned = [[UIAlertView alloc] initWithTitle:#"Done!" message:#"Your device is now clean. Restarting SpringBoard." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
Also, make sure that the class from which you are presenting the alert view declares the UIAlertViewDelegate protocol
//YourClass.h
#interface YourClass : SuperClass <UIAlertViewDelegate>

iOS: How to hook into MPMoviePlayerController?

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.

How to hook to a function to iOS alarms?

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

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.