NSBrainDump Sikosis's iPhone and OS X Development Blog http://xcode.sikosis.com/ Depot CMS More Dates with iOS Fri, 02 Dec 2011 10:11:00 +1000 2nd December, 2011 10:11 AM - I've been doing more iOS coding using Dates in various formats and hence I decided to add this post about it. Generally, you'll grab a date using the following:- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]); [dateFormatter release]; // Output: Dec 2, 2011 10:11 AM But say you just want the time ... [dateFormatter setDateFormat:@"hh:mm:ss"] // Output: 10:11:23 Now, let's say your want to specify something different. Well I couldn't find anything on the official Apple site about it, but I did find them listed on a blog, so I thought I'd reproduce them here:- a: AM/PM A: 0~86399999 (Millisecond of Day) c/cc: 1~7 (Day of Week) ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday d: 1~31 (0 padded Day of Month) D: 1~366 (0 padded Day of Year) e: 1~7 (0 padded Day of Week) E~EEE: Sun/Mon/Tue/Wed/Thu/Fri/Sat EEEE: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday F: 1~5 (0 padded Week of Month, first day of week = Monday) g: Julian Day Number (number of days since 4713 BC January 1) G~GGG: BC/AD (Era Designator Abbreviated) GGGG: Before Christ/Anno Domini h: 1~12 (0 padded Hour (12hr)) H: 0~23 (0 padded Hour (24hr)) k: 1~24 (0 padded Hour (24hr) K: 0~11 (0 padded Hour (12hr)) L/LL: 1~12 (0 padded Month) LLL: Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec LLLL: January/February/March/April/May/June/July/August/September/October/November/December m: 0~59 (0 padded Minute) M/MM: 1~12 (0 padded Month) MMM: Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec MMMM: January/February/March/April/May/June/July/August/September/October/November/December q/qq: 1~4 (0 padded Quarter) qqq: Q1/Q2/Q3/Q4 qqqq: 1st quarter/2nd quarter/3rd quarter/4th quarter Q/QQ: 1~4 (0 padded Quarter) QQQ: Q1/Q2/Q3/Q4 QQQQ: 1st quarter/2nd quarter/3rd quarter/4th quarter s: 0~59 (0 padded Second) S: (rounded Sub-Second) u: (0 padded Year) v~vvv: (General GMT Timezone Abbreviation) vvvv: (General GMT Timezone Name) w: 1~53 (0 padded Week of Year, 1st day of week = Sunday, NB: 1st week of year starts from the last Sunday of last year) W: 1~5 (0 padded Week of Month, 1st day of week = Sunday) y/yyyy: (Full Year) yy/yyy: (2 Digits Year) Y/YYYY: (Full Year, starting from the Sunday of the 1st week of year) YY/YYY: (2 Digits Year, starting from the Sunday of the 1st week of year) z~zzz: (Specific GMT Timezone Abbreviation) zzzz: (Specific GMT Timezone Name) Z: +0000 (RFC 822 Timezone) http://xcode.sikosis.com/index.php?blog=33 http://xcode.sikosis.com/index.php?rss=33 WWDC 2011 Session Videos Fri, 24 Jun 2011 06:20:00 +1000 24th June, 2011 06:20 AM - The WWDC 2011 Session videos are now available via iTunes. These HD videos can be downloaded, as long as you have a paid developer account -- which makes sense, as it's the developers who have accounts who will benefit from the content. Click here to get them. http://xcode.sikosis.com/index.php?blog=32 http://xcode.sikosis.com/index.php?rss=32 3 Ways to Show Activity Sat, 11 Jun 2011 10:38:00 +1000 11th June, 2011 10:38 AM - No matter what you're doing on the iOS, you will alway need to keep the user updated with what's going on at all times. One of the best ways to do that is using a UIActivityView; also know as one of those spinning things. Here I'm going to show you three (3) different ways of showing activity:- Method 1 - Using the Status Bar UIApplication* app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = YES; // to stop it, set to NO Method 2 - Using a UIBarButtonItem In your Header file add the following to your interface:- UIActivityIndicatorView *activityCustom; Also, add these methods to your Header. -(void)hideCustomActivity; -(void)showCustomActivity; Then flesh out those methods in your Implementation File:- #pragma mark - Custom activity -(void)showCustomActivity { activityCustom = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(-20,0,20,20)]; activityCustom.alpha = 1.0; [activityCustom startAnimating]; UIBarButtonItem *activityItem = [[UIBarButtonItem alloc] initWithCustomView:activityCustom]; self.navigationItem.rightBarButtonItem = activityItem; [activityItem release]; } -(void)hideCustomActivity { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; activityCustom.alpha = 0.0; [UIView commitAnimations]; } You can now hide and show the Activity using these methods. Method 3 - Using the UIActivityView on a XIB Add a UIActivityView to your XIB with the Hide when Stopped Animated setting on and glue it up to our IBOutlet called activity. IBOutlet UIActivityIndicatorView *activity; You can then call it by using the following:- [activity startAnimating]; // OR [activity stopAnimating]; Now you know how to give feedback to your users when you app is busy. Go forth! Source: UIActivityIndicatorView http://xcode.sikosis.com/index.php?blog=31 http://xcode.sikosis.com/index.php?rss=31 Make a Date with iOS Thu, 28 Apr 2011 07:06:00 +1000 28th April, 2011 07:06 AM - Here's a few lines of code on how you can utilize the date in your applications:- Using NSDate and NSCalendar to extract current year, month, and day NSDate *now = [NSDate date]; // Specify which units we would like to use unsigned units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [calendar components:units fromDate:now]; NSInteger year = [components year]; NSInteger month = [components month]; NSInteger day = [components day]; http://xcode.sikosis.com/index.php?blog=30 http://xcode.sikosis.com/index.php?rss=30 UIColor using RGB Tue, 08 Mar 2011 07:22:00 +1000 8th March, 2011 07:22 AM - When using colour (or color as the Americans prefer) in iOS for say, a text label or background, you can use the in-built colours such as:- [UIColor blackColor]; But what if you want to use something a little different ? Like a custom colour light blue ... UIColor *color = [UIColor colorWithRed:50/255.0 green:200/255.0 blue:255/255.0 alpha:1]; If you're stuck for inspiration, here's a link to an RGB Colour Picker. Source: UIColor http://xcode.sikosis.com/index.php?blog=29 http://xcode.sikosis.com/index.php?rss=29 Execute Unix scripts Mon, 13 Dec 2010 11:11:00 +1000 13th December, 2010 11:11 AM - One of the OS X applications I'm working on is going to bundle a set of tasks into a bash script and then fire off that script. The command to the rescue is the system() command, however, you need to convert the string to UTF-8 before you can do it. As an example, here's source code where I'm changing the permission on the script to make it executable. NSString *chmodCommand = @"chmod +x /tmp/task.sh"; const char *execChmod = [chmodCommand UTF8String]; system(execChmod); http://xcode.sikosis.com/index.php?blog=28 http://xcode.sikosis.com/index.php?rss=28 Detecting Text Field Focus Changes In Mac OS X Sun, 12 Dec 2010 04:14:00 +1000 12th December, 2010 04:14 AM - I needed to be able to tell if a user was in a particular textfield and so went looking for some code on how to work out which textfield has focus. I found some code and adapted it to work -- and here it is:- 1. Add the following code to your View Controller which is associated with the NSTextField. bool hasFocus(id theField) { return [[[theField window] firstResponder] isKindOfClass:[NSTextView class]] && [[theField window] fieldEditor:NO forObject:nil]!=nil && ( (id) [[theField window] firstResponder] ==theField || [(id) [[theField window] firstResponder] delegate]==theField); } 2. Add global references for these items:- int fieldActive; NSTimer *theTimer; 3. Kick off the timer in your ViewDidLoad or something similar ... theTimer=[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(handleTimerPulse:) userInfo:nil repeats:YES]; 4. Add the method to be fired off by the timer:- -(void)handleTimerPulse:(id) timer { int FIELD_A = 0; int FIELD_B = 1; if (fieldActive!= FIELD_A && hasFocus(TextField1)) { fieldActive = FIELD_A; NSLog(@"Focus - TextField1"); } if (fieldActive!= FIELD_B && hasFocus(TextField2)) { fieldActive =FIELD_B; NSLog(@"Focus - TextField2"); } } And that's how you do it! Reference: NSTextField http://xcode.sikosis.com/index.php?blog=27 http://xcode.sikosis.com/index.php?rss=27 iPhone 3.01 Xcode Fix Mon, 10 Aug 2009 01:23:00 +1000 10th August, 2009 01:23 AM - Apple latest update to the iPhone may have fixed the SMS hacking bug, however, it also stopped Xcode developers from being able to install their apps on their iPhones. Thankfully, there is a relatively painless fix. 1. Open Terminal 2. Type the following:- ln -s /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.0\ \(7A341\) /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.0.1 NB: If you are using 3.1 SDK, then remove the "\ \(7A341)" part, cause the folder name is "3.0" not "3.0 (7A341)" http://xcode.sikosis.com/index.php?blog=26 http://xcode.sikosis.com/index.php?rss=26 Greater Union Mobile Cinema Mon, 20 Apr 2009 09:45:00 +1000 20th April, 2009 09:45 AM - Looks like Greater Union has got with the times and is providing a mobile site that lets you check movie times, order tickets and reserve seating all from your web-enabled mobile phone. http://m.greaterunion.com.au/ http://xcode.sikosis.com/index.php?blog=25 http://xcode.sikosis.com/index.php?rss=25 Top Apps for 2008 Tue, 02 Dec 2008 08:32:00 +1000 2nd December, 2008 08:32 AM - Apple has released the Top Paid and Free apps for the iPhone for 2008. NB: Sorry about the broken images, but that's iTunes App Store for ya ;) http://xcode.sikosis.com/index.php?blog=24 http://xcode.sikosis.com/index.php?rss=24 iPhone Keyboard - Hide when Done Tue, 25 Nov 2008 04:56:00 +1000 25th November, 2008 04:56 AM - As a developer, I find this very frustrating and it's certainly one fo the first thing that iPhone developers come across and that's "How do I get rid of the keyboard, once text has been entered into a TextField ?" Unfortunately, the developer has to programatically control this behaviour, even though you'd think the Keyboard would just take care of things like this. Here's what you need to do:- 1) Add the following code to your .m file. -(BOOL)textFieldShouldReturn:(UITextField *) textField {    [textField resignFirstResponder];    return YES; } 2) In Interface Builder, you have to bind the delegate Outlet to the File's Owner. ie. itself. Now, when you click the "Done" button on your keyboard, it will close the keyboard like it should. http://xcode.sikosis.com/index.php?blog=23 http://xcode.sikosis.com/index.php?rss=23 2.2 Update Fixes Issues, Causes Others Sun, 23 Nov 2008 04:39:00 +1000 23rd November, 2008 04:39 AM - Apple's latest update for the iPhone, is causing a number of issues among iPhone and iPod touch users. It appears that some users are having issues deleting emails, SIM card problems along with slowiness accessing the App Store. Click here for the full story. http://xcode.sikosis.com/index.php?blog=22 http://xcode.sikosis.com/index.php?rss=22 31 Days of iPhone Apps Mon, 13 Oct 2008 11:28:00 +1000 13th October, 2008 11:28 AM - AppsAmuck.com has launched a web site called 31 Days of iPhone Apps. "We think sometimes people have a hard time taking those first steps. It is easy to think that it will take too much time, and that it will be too hard. But that is simply not the case. But instead of telling people, we are going to show them how easy it really is." Awesome. http://xcode.sikosis.com/index.php?blog=21 http://xcode.sikosis.com/index.php?rss=21 Apple Drops iPhone NDA Wed, 01 Oct 2008 08:30:00 +1000 1st October, 2008 08:30 AM - Apple released an official open letter on Apple.com to their developers stating that the NDA for released apps has been lifted, as well as explaining why it was put in place. This is awesome news, however, I can't help but feel that the G1 had something to do with this decision ;) http://xcode.sikosis.com/index.php?blog=20 http://xcode.sikosis.com/index.php?rss=20 Flash Coming to the iPhone, when Apple allow it Tue, 30 Sep 2008 04:40:00 +1000 30th September, 2008 04:40 AM - "At the Flash On The Beach (FOTB) conference in Brighton, Sr. Director of Engineering at Adobe Systems Paul Betlem, confirmed that Adobe is indeed developing a Flash Player for the iPhone. However, Apple calls the shots as to when it'll be available." http://xcode.sikosis.com/index.php?blog=19 http://xcode.sikosis.com/index.php?rss=19 iPhone 2.1 Update Tue, 09 Sep 2008 06:48:00 +1000 9th September, 2008 06:48 AM - Apple will release an update to the iPhone update on Saturday (AU) that promises to "fix alot of bugs", according to Jobs in today's keynote. The iPod Touch gets the update today. Personally, this has fixed pretty much all my issues with the iPhone. No longer do 3rd party apps crash or not work. Before, I was embarrassed to show off an app, just in case it didn't work -- but now, no issues, so it's all good. http://xcode.sikosis.com/index.php?blog=18 http://xcode.sikosis.com/index.php?rss=18 Leaked Video of Last.fm's iPhone App Tue, 02 Sep 2008 09:50:00 +1000 2nd September, 2008 09:50 AM - Click the picture above to watch the video. http://xcode.sikosis.com/index.php?blog=17 http://xcode.sikosis.com/index.php?rss=17 iPhone's 3G Antenna Reception - Just Fine Mon, 25 Aug 2008 07:15:00 +1000 25th August, 2008 07:15 AM - "Bluetest is a small company based in Lindholmen Science Park in Sweden that makes and sells testing chambers for small handheld wireless devices for companies like Motorola and OTC. They found that despite the connection issues being experienced by some, they were able to find nothing unusual with the device's hardware, saying "the values are completely normal." Their tests show that the iPhone 3G's antenna strength is comparable to the Nokia N73 and Sony Ericcson P1, which they tested under the same conditions." The full article can be found here. http://xcode.sikosis.com/index.php?blog=16 http://xcode.sikosis.com/index.php?rss=16 iPhone 2.0.2 Update Thu, 21 Aug 2008 10:49:00 +1000 21st August, 2008 10:49 AM - Apple has released a new update for the iPhone, version 2.02. The update whilst "it does work for others; it seems that it apparently does quite the opposite for some. More specifically, the latest update actually kills the iPhone’s ability to make phone calls in a 3G network. Ironic isn’t it considering that the whole point of owning a 3G iPhone is to be able to use it in a 3G network, right? Well, reports are coming in that some users are experiencing this dilemma after they have updated their beloved iPhone. One particular frustrated owner eventually brought his iPhone to an AT&T store to have it checked; and when the SIM was swapped out, the problem was fixed." http://xcode.sikosis.com/index.php?blog=14 http://xcode.sikosis.com/index.php?rss=14 Top 25 Free iPhone Web Apps for Your Daily Life Tue, 19 Aug 2008 12:00:00 +1000 19th August, 2008 12:00 PM - iPhoneToolbox.com has posted an article listing their Top 25 Free iPhone Web Apps for Your Daily Life. Check them out here. http://xcode.sikosis.com/index.php?blog=15 http://xcode.sikosis.com/index.php?rss=15 Apple To Fix Reception Issue WIth Software Update Thu, 14 Aug 2008 09:29:00 +1000 14th August, 2008 09:29 AM - "Users have been reporting unusually bad reception and an abundance of dropped calls on their iPhone 3Gs, leading one analyst to suggest that the Infineon chipset may be defective. Now a source of BusinessWeek corroborates the story, saying that Apple is aware of the situation and that the problem is in fact related to the chipset." Check out the rest of this article at iPhone Alley. http://xcode.sikosis.com/index.php?blog=13 http://xcode.sikosis.com/index.php?rss=13 iPhone 2.0.1 is here ! Mon, 04 Aug 2008 09:20:00 +1000 4th August, 2008 09:20 AM - According to Engadget, "Well, finally. iPhone firmware 2.0.1 has just been released by Apple, and we're hoping it solves the myriad problems introduced by 2.0: crashing apps, interminable keyboard delays, choppy scrolling." Also, AppleInsider notes the following:-You can now drag an app icon across multiple pages in one motion, rather than having to drag it, drop it, pick it up again and drag it over to next page, and repeat. Contacts are now more responsive. After installing 2.0.1, each successive backup is much faster. Apple may have changed the calibration of the iPhone's reception "bars" while connected to a 3G network to reflect a stronger signal than before. Keypad loads quicker. Screen rotation in Safari appears to be smoother. Some apps may ask to be updated after the firmware upgrade. http://xcode.sikosis.com/index.php?blog=12 http://xcode.sikosis.com/index.php?rss=12 Why you should buy locally Thu, 31 Jul 2008 05:46:00 +1000 31st July, 2008 05:46 AM - I've been wanting to get some cases for our iPhones, in particular, the DLO Jam Jacket for myself and the HipCase for my wife. After writing to Streetwise yesterday, I was told that these are not available in Australia and to "just keep an eye on their web site" for more. Great thanks for that. So, I figured I would price up buying these cases direct from the US. Total case $49.98 US for the two cases, however, because they use UPS for their shipping, the shipping cost is $82.64 US just for postage !!! I think I'll wait for a local distributor to stock these products ... http://xcode.sikosis.com/index.php?blog=9 http://xcode.sikosis.com/index.php?rss=9 Bug in Twitterrific causes issues with TwitPic Wed, 30 Jul 2008 06:31:00 +1000 30th July, 2008 06:31 AM - Twitterriffic, for those who don't know, is a Twitter client for the iPhone. It is probably the nicest looking one and works well enough for my needs. However, if you use this application to upload photos to TwitPic, they will appear in the wrong orientation. After getting frustrated about this yesterday and posting again to TwitPic asking if they'll fix this bug, they advised that it's actually a bug in Twitteriffic and not TwitPic. Here's hoping the good folks at IconFactory fix this fine app soon. http://xcode.sikosis.com/index.php?blog=8 http://xcode.sikosis.com/index.php?rss=8 Sync removes a truckload of apps Wed, 30 Jul 2008 06:00:00 +1000 30th July, 2008 06:00 AM - Last night, I hooked my iPhone up to sync and noticed it was taking a very long time to complete. I decided to leave it and see what would happen ... well, after 1 hour 14 minutes later ... it has completed a sync and in the process had removed a truckload of apps OFF my iPhone. I'm guess this is because of  either:- 1) These apps have been deemed "bad" by Apple and were removed from the AppStore. 2) These apps are now not available in the Australian iPhone AppStore and have hence been removed. 3) iTunes decided that what was on the iPhone didn't make and hence took off everything. This is unlikely  (I hope) and I'm starting to think it's more likley one of the first 2 options. I wonder if anyone else has had these issues ? http://xcode.sikosis.com/index.php?blog=7 http://xcode.sikosis.com/index.php?rss=7