Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 19    Views: 80

Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
09/21/12 03:01 PM (13 years ago)

FAO David or other expert coders Xcode

Hi guys, Sorry to post this here but i'm having a massive issue with a non BT app that I'm creating and wondered if anyone minded an opinion please? Basically its an alarm clock app. Nothing new here on the app store but it has a twist so hopefully will do OK. Now, on iOS 5,1 it works a treat. Guess what... On iOS 6 is crashes and doesnt like one line of code. Here: // This method is run every 0.5 seconds by the timer created // in the function runTimer - (void)showActivity { NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; NSDate *date = [NSDate date]; if(isAlarmOn == 1 && AlarmPlaying ==0){ alarmButton.hidden = NO; NSLog(@"Going to compare times"); NSDate *d = [date earlierDate:AlarmDate]; NSLog(@"Compared Times"); if (d == date) { NSLog(@"Current time earlier"); } else if (d == AlarmDate) { AlarmPlaying = 1; [self playAlarmSound]; } } The line: NSDate *d = [date earlierDate:AlarmDate]; returns an EXC_BAD_ACCESS error whenever the date picker is used to set the alarm. Does anyone have any suggestions please, or could it be an iOS 6 bug? Thanks so much and appreciate its non BT. All the best Alex
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/21/12 03:06 PM (13 years ago)
Oh, and one other thing which might effect BT. iOS6 seems temperamental on its allowance of UIWebView for streaming audio for radio apps (ive had some work and some crash) so i've decided to use MPMoviePlayerController to do the work. It actually works better in the sense that it doesnt go to the Quicktime standard screen. The issue I have is creating a stop button! The code: -(IBAction) playAudio:(id)sender { NSString *url = @"http://YOURURLHERE"; MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]]; [moviePlayer play]; } Again, ideas massively appreciated.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/21/12 10:44 PM (13 years ago)
I'll take a shot at these... Alarm First: In your method you are references a few properties that are outside the scope of this method. isAlarmOn AlarmPlaying alarmButton AlarmDate Are all four of these properties declared in the .h file and initialized somewhere else in your .m file, like in the viewDidLoad method? It's likely that AlarmDate or something is nil, or has no value and you're asking iOS to look at it's value with this line: NSDate *d = [date earlierDate:AlarmDate]; Also, because you're comparing isAlarmOn and AlarmPlaying to 1 or 0 (zero), it's logical that you've created these as integers. But, their names suggest they should be BOOL (boolean) instead. Either way is fine but generally it's best to use a naming convention that helps devs understand the dataType of the property without seeing the .h interface file and it's declaration. Like... int isAlarmPlaying could be easier to read if it were.. BOOL isAlarmPlaying Additionally, it's usually best to stick with a camelCase nameing convention for app properties. Like isAlarmPlaying (good) and alarmPlaying (lower case a) instead of AlarmPlaying. Just a semantics thing here and just trying to guide you in the right direction, not be nit-picky :-) So, start by fixing up your naming conventions on this file and think about them in future files. AND, figure out where AlarmDate (which should be alarmDate, wink) is getting a value before you reference it...bet it fixes it. On the stop button...you have a method that instantiates a new MPMoviePlayerController. You're allocating memory for it with the initWithContentURL and alloc mathed. Cool. Next, you're saying "play" - also cool. However, you'll not be able to access the moviePlayer you created inside another method. Why? Because you're creating it inside the playAudio method. You could change this idea by making the MPMoviePlayerController *moviePlayer a property of the class. Then, it would be available in all the methods in your .m file. Like... .h file: add.... MPMoviePlayerController *moviePlayer; AND @property (nonatomic, retain) MPMoviePlayerController *moviePlayer; .m file, add... @synthesize moviePlayer; (with the other properties you're synthesizing)... Init the moviePlayer property to nil in the viewDidLoad method... self.moviePlayer = nil; So far so good. Next, modify the play method so it references the existing moviePlayer property instead of creating a new one... -(IBAction) playAudio:(id)sender { NSString *url = @"http://YOURURLHERE"; self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:url]]; [moviePlayer play]; } now you can access it in your stop method... -(IBAction) stopAudio:(id)sender{ //if we have a player, stop it! if(self.moviePlayer != nil){ [moviePlayer stop]; //set it to nil for next time.. self.moviePlayer = nil; } } Naturally there are all sorts of ways to do this kinda thing and the best way will depend on othe design and programming goals...but...this should get you going. Let me know if the AlarmDate, oh, wait, alarmDate (ha!) gets worked out.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/22/12 02:05 AM (13 years ago)
Thanks David, you are a godSend!! Here is the .h #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> #import <AVFoundation/AVFoundation.h> @interface FirstViewController : UIViewController <AVAudioPlayerDelegate>{ IBOutlet UILabel* clockLabel; IBOutlet UILabel* AmPmLabel; IBOutlet UILabel* AlarmLabel; IBOutlet UIImageView *imageView; NSTimer *myTicker; IBOutlet UIButton *alarmButton; //SystemSoundID systemSoundID; AVAudioPlayer *player; AVAudioPlayer *audioPlayer; IBOutlet UITabBar *myTabBar;// } @property(nonatomic,retain) IBOutlet UILabel* clockLabel; @property(nonatomic,retain) IBOutlet UILabel* AmPmLabel; @property(nonatomic,retain) IBOutlet UILabel* AlarmLabel; @property(nonatomic,retain) IBOutlet UIImageView *imageView; @property(nonatomic,retain) IBOutlet UIButton *alarmButton; @property (nonatomic, retain) IBOutlet AVAudioPlayer *player; - (void) runTimer; - (void)showActivity; -(void) playAlarmSound; -(IBAction)AlarmOff:(id)sender; @end There is other stuff going on here as well as playing the alarm. Here is the .m in its entirety #import "FirstViewController.h" #import <AudioToolbox/AudioToolbox.h> #import "globals.h" @implementation FirstViewController @synthesize clockLabel, AmPmLabel,AlarmLabel,alarmButton; -(IBAction)AlarmOff:(id)sender{ [audioPlayer stop]; alarmButton.hidden = YES; [AlarmLabel setText:@"ALARM OFF"]; isAlarmOn = 0; AlarmPlaying = 0; UITabBarItem *tabBarItem = [[myTabBar items] objectAtIndex:1]; [tabBarItem setEnabled:TRUE]; } -(void) playAlarmSound{ NSString *soundFile; if(AlarmPlaying == 1){ switch(soundFileIndex){ case 0: soundFile = [[NSString alloc]initWithString:@"1"]; break; case 1: soundFile = [[NSString alloc]initWithString:@"2"]; break; case 2: soundFile = [[NSString alloc]initWithString:@"3"]; break; case 3: soundFile = [[NSString alloc]initWithString:@"4"]; break; case 4: soundFile = [[NSString alloc]initWithString:@"5"]; break; case 5: soundFile = [[NSString alloc] initWithString:@"6"]; break; case 6: soundFile = [[NSString alloc]initWithString:@"7"]; break; case 7: soundFile = [[NSString alloc]initWithString:@"8"]; break; case 8: soundFile = [[NSString alloc]initWithString:@"9"]; break; case 9: soundFile = [[NSString alloc]initWithString:@"10"]; break; case 10: soundFile = [[NSString alloc]initWithString:@"11"]; break; case 11: soundFile = [[NSString alloc]initWithString:@"12"]; break; case 12: soundFile = [[NSString alloc]initWithString:@"13"]; break; case 13: soundFile = [[NSString alloc]initWithString:@"14"]; break; case 14: soundFile = [[NSString alloc]initWithString:@"15"]; break; case 15: soundFile = [[NSString alloc]initWithString:@"16"]; break; case 16: soundFile = [[NSString alloc]initWithString:@"17"]; break; case 17: soundFile = [[NSString alloc]initWithString:@"18"]; break; case 18: soundFile = [[NSString alloc]initWithString:@"19"]; break; case 19: soundFile = [[NSString alloc]initWithString:@"20"]; case 20: soundFile = [[NSString alloc]initWithString:@"21"]; break; case 21: soundFile = [[NSString alloc]initWithString:@"22"]; break; case 22: soundFile = [[NSString alloc]initWithString:@"23"]; break; case 23: soundFile = [[NSString alloc]initWithString:@"24"]; break; case 24: soundFile = [[NSString alloc]initWithString:@"25"]; break; case 25: soundFile = [[NSString alloc]initWithString:@"26"]; break; case 26: soundFile = [[NSString alloc]initWithString:@"27"]; break; case 27: soundFile = [[NSString alloc]initWithString:@"28"]; break; case 28: soundFile = [[NSString alloc]initWithString:@"29"]; break; case 29: soundFile = [[NSString alloc]initWithString:@"30"]; break; }//end switch statement NSMutableString *myFileName = [[NSMutableString alloc] initWithString:[[NSBundle mainBundle] resourcePath]]; [myFileName appendString:@"/"]; [myFileName appendString:soundFile]; if(soundFileIndex == 5 || soundFileIndex == 2) [myFileName appendString:@".m4r"]; else { [myFileName appendString:@".m4r"]; } NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:myFileName]]; NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; audioPlayer.numberOfLoops = -1; [audioPlayer play]; } } - (void)runTimer { // This starts the timer which fires the showActivity // method every 0.5 seconds myTicker = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector(showActivity) userInfo: nil repeats: YES]; } // This method is run every 0.5 seconds by the timer created // in the function runTimer - (void)showActivity { NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; NSDate *date = [NSDate date]; if(isAlarmOn == 1 && AlarmPlaying ==0){ alarmButton.hidden = NO; NSLog(@"Going to compare times"); NSDate *d = [date earlierDate:AlarmDate]; NSLog(@"Compared Times"); if (d == date) { NSLog(@"Current time earlier"); } else if (d == AlarmDate) { AlarmPlaying = 1; [self playAlarmSound]; } } // This will produce a time that looks like "12:15:00 PM". [formatter setTimeStyle:NSDateFormatterMediumStyle]; // This sets the label with the updated time. [clockLabel setText:[formatter stringFromDate:date]]; } /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { imageView.contentMode=UIViewContentModeScaleAspectFill; [imageView setFrame:CGRectMake(50, 350,700,300)]; [clockLabel setFrame:CGRectMake(420,547,504,207)]; } else { //configuration for portrait imageView.contentMode=UIViewContentModeScaleAspectFill; [imageView setFrame:CGRectMake(150, 75,704,500)]; [clockLabel setFrame:CGRectMake(240,800,504,207)]; } } } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; //*********** iPad Specific Code **************************** if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { imageView.contentMode=UIViewContentModeScaleAspectFill; [imageView setFrame:CGRectMake(125, 150,525,600)]; [clockLabel setFrame:CGRectMake(240,800,504,207)]; } else { imageView.contentMode=UIViewContentModeScaleAspectFill; [imageView setFrame:CGRectMake(50, 350,700,300)]; [clockLabel setFrame:CGRectMake(420,547,504,207)]; } } //************************************************************ AlarmPlaying = 0; //[clockLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:75.0]]; [self runTimer]; soundFileIndex = 5; } // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { BOOL isPad; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ isPad = YES; } else { isPad = (interfaceOrientation == UIInterfaceOrientationPortrait); } return (isPad); } -(void)viewDidAppear:(BOOL)animated{ if(ImageSelected == 1){ NSString *stringNum = [[NSString alloc] initWithFormat:@"%d",ImageNumber]; NSMutableString *strImage = [[NSMutableString alloc] initWithString:@"horse"]; [strImage appendString:stringNum]; NSString *imageType = [[NSString alloc] initWithString:@".jpg"]; [strImage appendString:imageType]; imageView.image = [UIImage imageNamed:strImage]; [stringNum release]; [strImage release]; [imageType release]; } if(isAlarmOn == 1){ NSMutableString *alarmString = [[NSMutableString alloc]initWithString:@"ALARM ON "]; // This will produce a time that looks like "12:15:00 PM". NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setTimeStyle:NSDateFormatterShortStyle]; // This sets the label with the updated time. NSString *temp = [[NSString alloc] initWithString:[formatter stringFromDate:AlarmDate]]; [alarmString appendString:temp]; [AlarmLabel setText:alarmString]; [temp release]; [alarmString release]; } else { [AlarmLabel setText:@"ALARM OFF"]; alarmButton.hidden = YES; } if(ColorChanged == 1){ switch(ClockColor){ case 0://green clockLabel.textColor = [UIColor redColor]; AlarmLabel.textColor = [UIColor redColor]; break; case 1://Blue clockLabel.textColor = [UIColor blueColor]; AlarmLabel.textColor = [UIColor blueColor]; break; case 2://Red clockLabel.textColor = [UIColor greenColor]; AlarmLabel.textColor = [UIColor greenColor]; break; case 3://Black clockLabel.textColor = [UIColor blackColor]; AlarmLabel.textColor = [UIColor blackColor]; break; case 4://white clockLabel.textColor = [UIColor whiteColor]; AlarmLabel.textColor = [UIColor whiteColor]; break; case 5: clockLabel.textColor = [UIColor orangeColor]; AlarmLabel.textColor = [UIColor orangeColor]; break; default: break; } ColorChanged = 0; } } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end As you can see, Globals.h is declaring the properties: Global.h NSDate *AlarmDate; int isAlarmOn;//1 = YES 0 = No NSInteger soundFileIndex; int ImageNumber; int ImageSelected; //1=Yes,0 = No int ClockColor; int ColorChanged; int AlarmPlaying; I am obviously at a loss but also confused that it worked fine on iOS 5,1 ut not 6. That said, your time and effort to assist me with a fix is so appreciated. allTheBest!!
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/22/12 03:24 AM (13 years ago)
With regards the movieplayer, it worked like an absolute charm, many, many thanks. :)
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/22/12 03:44 AM (13 years ago)
Sorry, just to add. I have added the NSDate *alarmDate; to the firstview.h which has helped in the sense that this line appears no longer to be an issue and the alarm sets but it crashes out when returning to the first View! I'm trying and cant be far off! Thanks.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/22/12 05:02 PM (13 years ago)
Also have got the audio playing in the background using the same methods as here, creating an array and string in the .plist, creating an audiosession delegate and adding the following to the radio.m //Adds ability for audio to play even in screen lock NSError *setCategoryErr = nil; NSError *activationErr = nil; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr]; [[AVAudioSession sharedInstance] setActive: YES error: &activationErr]; } So close with the alarm setting, any ideas David? Its getting its value in viewDidAppear as you can see above. Many thanks :)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/23/12 05:36 PM (13 years ago)
OK, back to this. For the alarm, you mention... "the alarm sets but it crashes out when returning to the first View" I'm not quite sure what this means. We'll need to know EXACTLY what you press or what event is happening when it crashes. When the screen loads? When the alarm is set? When the back button is pressed? etc. Try to explain in detail the order of events that create the crash. Detective work!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/23/12 05:58 PM (13 years ago)
BEFORE responding to the previous question, update your code with the following two posts. One is the .h and one is the .m. Your source was filled with references to properties that were undeclared in the .h file and un synthesized in the .m file. I realize you may not know what this is. More on that later. These updated files may or may not fix your issue (I still don't know what it does without the .xib file) but they don't have any errors :-) Next post: .h file contents. Past after that: .m file contents
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/23/12 05:58 PM (13 years ago)
// // FirstViewController.h // // #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> #import <AVFoundation/AVFoundation.h> @interface FirstViewController : UIViewController <AVAudioPlayerDelegate>{ IBOutlet UILabel* clockLabel; IBOutlet UILabel* AmPmLabel; IBOutlet UILabel* AlarmLabel; IBOutlet UIImageView *imageView; NSTimer *myTicker; IBOutlet UIButton *alarmButton; //SystemSoundID systemSoundID; AVAudioPlayer *player; AVAudioPlayer *audioPlayer; IBOutlet UITabBar *myTabBar; int isAlarmOn; int AlarmPlaying; int soundFileIndex; int ImageSelected; int ImageNumber; int ClockColor; int ColorChanged; NSDate *AlarmDate; } @property(nonatomic,retain) IBOutlet UILabel* clockLabel; @property(nonatomic,retain) IBOutlet UILabel* AmPmLabel; @property(nonatomic,retain) IBOutlet UILabel* AlarmLabel; @property(nonatomic,retain) IBOutlet UIImageView *imageView; @property(nonatomic,retain) IBOutlet UIButton *alarmButton; @property (nonatomic, retain) IBOutlet AVAudioPlayer *player; @property (nonatomic, retain) IBOutlet AVAudioPlayer *audioPlayer; @property (nonatomic, retain) NSTimer *myTicker; @property (nonatomic, retain) UITabBar *myTabBar; @property (nonatomic) int isAlarmOn; @property (nonatomic) int AlarmPlaying; @property (nonatomic) int soundFileIndex; @property (nonatomic) int ImageSelected; @property (nonatomic) int ImageNumber; @property (nonatomic) int ClockColor; @property (nonatomic) int ColorChanged; @property (nonatomic, retain) NSDate *AlarmDate; -(IBAction)AlarmOff:(id)sender; -(void) playAlarmSound; -(void)runTimer; -(void)showActivity; -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; -(void)viewDidLoad; -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; -(void)viewDidAppear:(BOOL)animated; -(void)didReceiveMemoryWarning; -(void)viewDidUnload; - (void)dealloc; @end
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/23/12 05:58 PM (13 years ago)
// // FirstViewController.m // // #import "FirstViewController.h" #import <AudioToolbox/AudioToolbox.h> @interface FirstViewController () @end @implementation FirstViewController @synthesize clockLabel, AmPmLabel, AlarmLabel, imageView, myTicker, alarmButton, player, audioPlayer, myTabBar; @synthesize isAlarmOn, AlarmPlaying, soundFileIndex, AlarmDate, ImageSelected, ImageNumber, ClockColor, ColorChanged; -(IBAction)AlarmOff:(id)sender{ [audioPlayer stop]; alarmButton.hidden = YES; [AlarmLabel setText:@"ALARM OFF"]; isAlarmOn = 0; AlarmPlaying = 0; UITabBarItem *tabBarItem = [[myTabBar items] objectAtIndex:1]; [tabBarItem setEnabled:TRUE]; } -(void) playAlarmSound{ NSString *soundFile; if(AlarmPlaying == 1){ switch(soundFileIndex){ case 0: soundFile = [[NSString alloc]initWithString:@"1"]; break; case 1: soundFile = [[NSString alloc]initWithString:@"2"]; break; case 2: soundFile = [[NSString alloc]initWithString:@"3"]; break; case 3: soundFile = [[NSString alloc]initWithString:@"4"]; break; case 4: soundFile = [[NSString alloc]initWithString:@"5"]; break; case 5: soundFile = [[NSString alloc] initWithString:@"6"]; break; case 6: soundFile = [[NSString alloc]initWithString:@"7"]; break; case 7: soundFile = [[NSString alloc]initWithString:@"8"]; break; case 8: soundFile = [[NSString alloc]initWithString:@"9"]; break; case 9: soundFile = [[NSString alloc]initWithString:@"10"]; break; case 10: soundFile = [[NSString alloc]initWithString:@"11"]; break; case 11: soundFile = [[NSString alloc]initWithString:@"12"]; break; case 12: soundFile = [[NSString alloc]initWithString:@"13"]; break; case 13: soundFile = [[NSString alloc]initWithString:@"14"]; break; case 14: soundFile = [[NSString alloc]initWithString:@"15"]; break; case 15: soundFile = [[NSString alloc]initWithString:@"16"]; break; case 16: soundFile = [[NSString alloc]initWithString:@"17"]; break; case 17: soundFile = [[NSString alloc]initWithString:@"18"]; break; case 18: soundFile = [[NSString alloc]initWithString:@"19"]; break; case 19: soundFile = [[NSString alloc]initWithString:@"20"]; case 20: soundFile = [[NSString alloc]initWithString:@"21"]; break; case 21: soundFile = [[NSString alloc]initWithString:@"22"]; break; case 22: soundFile = [[NSString alloc]initWithString:@"23"]; break; case 23: soundFile = [[NSString alloc]initWithString:@"24"]; break; case 24: soundFile = [[NSString alloc]initWithString:@"25"]; break; case 25: soundFile = [[NSString alloc]initWithString:@"26"]; break; case 26: soundFile = [[NSString alloc]initWithString:@"27"]; break; case 27: soundFile = [[NSString alloc]initWithString:@"28"]; break; case 28: soundFile = [[NSString alloc]initWithString:@"29"]; break; case 29: soundFile = [[NSString alloc]initWithString:@"30"]; break; }//end switch statement NSMutableString *myFileName = [[NSMutableString alloc] initWithString:[[NSBundle mainBundle] resourcePath]]; [myFileName appendString:@"/"]; [myFileName appendString:soundFile]; if(soundFileIndex == 5 || soundFileIndex == 2) [myFileName appendString:@".m4r"]; else { [myFileName appendString:@".m4r"]; } //syntax error on this line... //NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:myFileName]]; NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@", myFileName]]; NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; audioPlayer.numberOfLoops = -1; [audioPlayer play]; } } - (void)runTimer { // This starts the timer which fires the showActivity // method every 0.5 seconds myTicker = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector(showActivity) userInfo: nil repeats: YES]; } // This method is run every 0.5 seconds by the timer created // in the function runTimer - (void)showActivity { NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; NSDate *date = [NSDate date]; if(isAlarmOn == 1 && AlarmPlaying ==0){ alarmButton.hidden = NO; NSLog(@"Going to compare times"); NSDate *d = [date earlierDate:AlarmDate]; NSLog(@"Compared Times"); if (d == date) { NSLog(@"Current time earlier"); } else if (d == AlarmDate) { AlarmPlaying = 1; [self playAlarmSound]; } } // This will produce a time that looks like "12:15:00 PM". [formatter setTimeStyle:NSDateFormatterMediumStyle]; // This sets the label with the updated time. [clockLabel setText:[formatter stringFromDate:date]]; } /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { imageView.contentMode=UIViewContentModeScaleAspectFill; [imageView setFrame:CGRectMake(50, 350,700,300)]; [clockLabel setFrame:CGRectMake(420,547,504,207)]; } else { //configuration for portrait imageView.contentMode=UIViewContentModeScaleAspectFill; [imageView setFrame:CGRectMake(150, 75,704,500)]; [clockLabel setFrame:CGRectMake(240,800,504,207)]; } } } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; //*********** iPad Specific Code **************************** if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { imageView.contentMode=UIViewContentModeScaleAspectFill; [imageView setFrame:CGRectMake(125, 150,525,600)]; [clockLabel setFrame:CGRectMake(240,800,504,207)]; } else { imageView.contentMode=UIViewContentModeScaleAspectFill; [imageView setFrame:CGRectMake(50, 350,700,300)]; [clockLabel setFrame:CGRectMake(420,547,504,207)]; } } //************************************************************ AlarmPlaying = 0; //[clockLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:75.0]]; [self runTimer]; soundFileIndex = 5; } // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { BOOL isPad; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ isPad = YES; } else { isPad = (interfaceOrientation == UIInterfaceOrientationPortrait); } return (isPad); } -(void)viewDidAppear:(BOOL)animated{ if(ImageSelected == 1){ NSString *stringNum = [[NSString alloc] initWithFormat:@"%d",ImageNumber]; NSMutableString *strImage = [[NSMutableString alloc] initWithString:@"horse"]; [strImage appendString:stringNum]; NSString *imageType = [[NSString alloc] initWithString:@".jpg"]; [strImage appendString:imageType]; imageView.image = [UIImage imageNamed:strImage]; [stringNum release]; [strImage release]; [imageType release]; } if(isAlarmOn == 1){ NSMutableString *alarmString = [[NSMutableString alloc]initWithString:@"ALARM ON "]; // This will produce a time that looks like "12:15:00 PM". NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setTimeStyle:NSDateFormatterShortStyle]; // This sets the label with the updated time. NSString *temp = [[NSString alloc] initWithString:[formatter stringFromDate:AlarmDate]]; [alarmString appendString:temp]; [AlarmLabel setText:alarmString]; [temp release]; [alarmString release]; } else { [AlarmLabel setText:@"ALARM OFF"]; alarmButton.hidden = YES; } if(ColorChanged == 1){ switch(ClockColor){ case 0://green clockLabel.textColor = [UIColor redColor]; AlarmLabel.textColor = [UIColor redColor]; break; case 1://Blue clockLabel.textColor = [UIColor blueColor]; AlarmLabel.textColor = [UIColor blueColor]; break; case 2://Red clockLabel.textColor = [UIColor greenColor]; AlarmLabel.textColor = [UIColor greenColor]; break; case 3://Black clockLabel.textColor = [UIColor blackColor]; AlarmLabel.textColor = [UIColor blackColor]; break; case 4://white clockLabel.textColor = [UIColor whiteColor]; AlarmLabel.textColor = [UIColor whiteColor]; break; case 5: clockLabel.textColor = [UIColor orangeColor]; AlarmLabel.textColor = [UIColor orangeColor]; break; default: break; } ColorChanged = 0; } } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/24/12 02:05 AM (13 years ago)
No errors David but instead it sets the alarm, produces the alert "Alarm Set at XX:XX" and can return to first View OK, which is where the clock is displayed, the label alarm clock on XX:XX or Alarm Clock off. The alarm isnt now setting, so the alarm on XX:XX doesnt update and the button which appears to turn the alarm off when its set isnt there either. Trying to work the solution myself, will ley you know if unable to if thats ok? Regards Alex
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/24/12 02:12 AM (13 years ago)
yup...totally OK. Just caught me before bed, it's 2:00 AM! LOL. You could also email me the .xib file you're using. I setup the class files in a project but dont' have the .xib. I thought about making one but didn't want to assume / guess about how it's setup. No worries...see if you can isolate the trouble, else send me the xib and I'll figure it out.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/24/12 02:16 AM (13 years ago)
Brilliant. Which address? [email protected]? You are a legend, not a word used lightly!
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/24/12 09:23 AM (13 years ago)
Emailed to David@buzztouch email address. All the best.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/25/12 12:16 AM (13 years ago)
Have the project you sent...looking into this now...stay tuned.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/25/12 01:23 AM (13 years ago)
Check your email.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/25/12 11:48 AM (13 years ago)
Cheers David, it has been returned to you via email! All the best.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/26/12 01:11 AM (13 years ago)
Fixed. See email.
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
09/26/12 12:21 PM (13 years ago)
Another reply on its way :/
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.