AVAudioPlayer *backgroundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Fishtank_Bubbles-SoundBibleco-amanda-1550139304-attribution3" ofType:@"wav"]] error:nil];
[backgroundPlayer setNumberOfLoops:-1];
[backgroundPlayer play];
Play Sound
iPhone SDK Tips & Tricks
Labels:
iphone SDK,
loop,
wav
Add Event in iCal or Calendar
iPhone SDK Tips & Tricks
Add EventKit.framework
Add EventKit.framework
#import <EventKit/EventKit.h>
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *newEvent = [EKEvent eventWithEventStore:eventStore];
newEvent.title = @"Event Title";
newEvent.startDate = [NSDate date];
newEvent.endDate = certDatePicker.date;
//newEvent.location = event.location;
newEvent.notes = @"Note for the event";
//EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-86400]; // 1 Day
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-86400*30]; // 30 Day
EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-86400*60]; // 60 Day
[newEvent addAlarm:alarm1];
[newEvent addAlarm:alarm2];
[newEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:newEvent span:EKSpanThisEvent error:&err];
Number Format
iPhone SDK Tips & Tricks
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
//[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setCurrencySymbol:@"Rp. "];
[numberFormatter setMaximumFractionDigits:0];
[numberFormatter setCurrencyGroupingSeparator:@"."];
//[numberFormatter setCurrencyCode:@"IDR"];
NSString *itemName = [numberFormatter stringFromNumber:[NSNumber numberWithInt:total]];
Labels:
currency,
format,
iphone SDK,
number
Creating Multithread
iPhone SDK Tips & Tricks
- (void) startNewThread {
// this kicks off a new thread like bruce-lee
[self performSelectorOnMainThread:@selector(loading) withObject:nil waitUntilDone:NO];
[NSThread detachNewThreadSelector:@selector(doNewThreadStuff) toTarget:self withObject:nil];
}
- (void)loading
{
if(looping)
{
//do loading animation
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(loading) userInfo:nil repeats:NO];
}
}
- (void) doNewThreadStuff {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// this is where you do your stuffs that takes forever and 2 days and 3 minutes
// then when done, you call the following to get back on track
[self performSelectorOnMainThread:@selector(newThreadDone) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void) newThreadDone {
// yay we finished, now continue onwards and upwards. maybe sideways a bit too.
}
Labels:
iphone SDK,
loading,
multi tasking,
multithread,
nsthread,
thread
Remove or Release NSTimer
iPhone SDK Tips & Tricks
-(void)startTimer { [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerFire:) userInfo:nil repeats:YES]; //Don't forget the colon after timerFire if it has an argument!! } -(void)timerFire:(NSTimer*)theTimer { //Do timer stuff here if (shouldKillTimer) [theTimer invalidate]; }
OR
[self performSelector:@selector(timerFunction) withObject:nil afterDelay:timeInSeconds];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(timerfunction) object:nil];
Labels:
cancel,
iphone SDK,
nstimer,
release
Draw Route or Direction
iPhone SDK Tips & TricksDownload http://blog.kadirpekel.com/wp-content/uploads/MapWithRoutes.zip
Include MapView, Place, PlaceMark, and RegexKitLite file (.h and .m) to your code
Target Info, find Other Linker Flags, add "-licucore"
code:
MapView* mapView = [[[MapView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)] autorelease]; |
[self.view addSubview:mapView]; |
Place* home = [[[Place alloc] init] autorelease]; |
home.name = @"Home"; |
home.description = @"Sweet home"; |
home.latitude = 41.029598; |
home.longitude = 28.972985; |
Place* office = [[[Place alloc] init] autorelease]; |
office.name = @"Office"; |
office.description = @"Bad office"; |
office.latitude = 41.033586; |
office.longitude = 28.984546; |
[mapView showRouteFrom:home to:office]; |
source:
http://blog.kadirpekel.com/2010/05/30/drawing_routes_onto_mkmapview_using_unofficial_google_maps_directions_api/
Get iPhone UDID
iPhone SDK Tips & Tricks
NSLog(@"iPhone udid: %@", [UIDevice currentDevice].uniqueIdentifier);
Labels:
iphone SDK
UIButton title and image alignment
iPhone SDK Tips & Tricks
[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
Labels:
iphone SDK
Make a Phone Call
iPhone SDK Tips & Tricks
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:1-877-829-7902"]];
Labels:
iphone SDK
Subscribe to:
Posts (Atom)