Showing posts with label apple. Show all posts
Showing posts with label apple. Show all posts

Monday, August 1, 2011

Indispensable iOS Development Documentation

I was just asked for my recommendation on the most indispensable iOS development documents available from Apple. Here is my response.

Publicly available documentation
Available to registered Apple Developer Program users

Tuesday, July 26, 2011

Road to devLink: View Controllers, Web View, Services, and Tests

I am writing this post after pushing the following commits:


iOS App: a862663

Server: N/A


Open Terminal, navigate to a nice place where you would like to store this code, and then perform the following to view this commit

git clone git@github.com:danielnorton/CandyStore-app.git --branch development
cd CandyStore-app/
git checkout a862663

In this commit, I have set up the main view controllers of the iOS app, I have also set up the first vestiges of a few of the services that the app will use, and I have written a few unit tests.


View Controllers

You will see that in MainWindow.xib I have set up a UITabBarController with three tabs. Each tab holds a UINavigationController that then each hold one of the three root view controllers that represent the three distinct sections of the app (My Candy Jar, Candy Shop, and Candy Exchange).


In my devLink session, I will probably discuss this approach. I have the idea in my head that I will have this completed app and then do separate branches or something like that to implement discrete portions of the app that are pertinent to the topic at hand. So, when I am talking about view controllers, I will (in advance) create a branch of the completed app that does not have this initial setup built. Then we can step through creating tab view controllers and navigation controllers, etc. We can see how to wire them up in Interface Builder and talk about how every thing that is done in Interface Builder can be done in code.


Services

As discussed above, there are three tabs. If a user is not currently subscribed to the Candy Exchange and they tap on the Exchange tab, I would like for the app to alert them to visit the Candy Shop and subscribe to the exchange. To facilitate this, I have registered the app delegate as a UITabBarControllerDelegate. That will notify me when the tab is tapped. All of the logic to test the current state of the user’s subscription and decide if the app should notify is contained in a service. At the moment, there isn’t much logic in the service. It will probably get more fleshed out as I add a model and wire up to In-App Purchasing and my own web services. But for now, I can still build the concept that some amount of work needs to be done, and that work needs to be contained in a service. When the complexity comes later, I can change the service without having to do much work (if any) outside of it.


When the service communicates back to the app delegate, the app delegate will display a UIAlertView. When all you need is a to display a modal message to the user, it gets somewhat tedious to fill in the big init method on UIAlertView. For situations like this, I am a big fan of categories. I have created a category for this situation called UIViewController+popup. I will use this at devLink as an example of categories and how to use them.


... hmm ... I have used UIViewController+popup in a number of projects. It’s one of my little “toolbelt items”. While writing this post, the thought occurred to me that tying the popup method to a UIViewController is not necessary ... I will leave it there for now. Maybe somebody at devLink will catch it and start a good discussion.


Tests

I am a big fan of TDD, but to be honest, I am not rigorous about using it. Additionally, I don’t find the testing tools built in to Xcode to be very good. The mocking tools I see out there aren’t terribly impressive to me, and I have yet to find an IoC container / framework. So, I really don’t write a lot of iOS unit tests. But since part of this project is for my own education, I am going to make a new concerted effort. Since the services I am writing at the moment are still self contained this is working out pretty well. Here is an example of a test and, as tests go, an example of how to use one of my services (with a huge name that I don’t like typing over and over).

- (void)testShouldNotAlertUserPurchaseExchange_IncrementThree {

ExchangeSubscriptionNotificationService *service = [[ExchangeSubscriptionNotificationService alloc] init];

[service reset];
service.counter++;
service.counter++;
BOOL shouldNotify = service.shouldNotify;
[service release];

STAssertFalse(shouldNotify, @"should not notify.");
}

When I get a little meatier code, I intend on writing a post about my preferred coding style and how I like to structure the contents of the .m and .h files. service.counter++; violates my preferred style, but it works in this instance so I am not going to get all excited. My preferred style would end up as something like: [server setCounter:service.counter + 1]; which is kind of ugly in this particular scenario.


Web View

If a user has not yet purchased any candy, instead of showing an empty list for the Candy Jar view controller (the first tab), I would like to show a welcome view. I thought it might be helpful to demonstrate the use of a UIWebView in showing this welcome message. I wanted to build a single ... welcome.html ... file to embed in the app. I fumbled along with Safari Mobile CSS stuff and decided to punt and see if I could get some cheats from Dashcode. It turns out I was able to put together a rudimentary welcome view very easily in Dashcode. It only took a few minutes. I kind of liked it. It is not fancy, and it really doesn’t end up looking as whiz-bang as I wanted. I really wanted to build a thing that used multiple colors on a single line of text or something like that which would be difficult with UILabel. But, anyway, it will work for now. I will show that off at devLink. The web view is in My Candy Jar view controller. It includes a good opportunity to demonstrate a simple animated fade in for the web view when it completes loading its content. Also, this view controller will offer a good talking point of how and when to use a UITableViewController and when to use a regular UIViewController that implements UITableViewDelegate and UITableViewDataSource. For this controller, I chose the latter. This will also make a good talking point when introducing protocols and delegation in my devLink talks.


Friday, July 22, 2011

Notes from Debugging live apps in the App Store

I recently released an app to the App Store. We are getting reports back from users that the app crashes on certain versions of iOS. Following are the steps I took to figure out the cause of the crash.
  • Firstly, I logged in to iTunes Connect
  • clicked "Manage Your Applications" -> MyApp -> View Details -> Crash Reports
  • downloaded the crash report to my local machine and unzipped it
  • opened Xcode -> Organizer -> Archives
  • selected the build that I had submitted to the App Store, control-clicked it, chose Show in Finder
  • control-clicked the .xcarchive file and chose "Show Package Contents"
  • copied the files /dSYMs/myapp.app.dSYM and /Products/Applications/myapp
  • pasted these files in the same directory as the unzipped crash reports. The contents of that folder looked something like this:
MyApp_1-1_2011-07-22_iOS-5-0_Top-Crash_1_1.crash
MyApp_1-1_2011-07-22_iOS-5-0_Top-Crash_1_2.crash
MyApp_1-1_2011-07-22_iOS-5-0_Top-Crash_1_3.crash
myapp.app
myapp.app.dSYM
  • I opened the first crash report, MyApp_1-1_2011-07-22_iOS-5-0_Top-Crash_1_1.crash, in a text editor. Here's what the first little bit looked like:
Date/Time:       2011-07-19 14:44:19.660 -0700
OS Version: iPhone OS X.X (XXXXXXX)
Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0xa0020008
Crashed Thread: 0

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3490807c objc_msgSend + 20
1 Foundation 0x31f2e2a4 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
2 UIKit 0x359071bc -[NSIndexPath(UITableView) row]
3 myapp 0x0000a728 0x0000a728
4 myapp 0x0000a074 0x0000a074
...

Thread 0 is the thread that crashed. Below the statement "Thread 0 Crashed:" you can see the first few lines of the offending backtrace log. Each line is the next level up in the backtrace, also called a stack frame. Stack frame 0 is the message that crashed, it was called by stack frame 1 which was called by stack frame 2, etc.

The first thing I looked for is _my_ code that was nearest the top of the call stack. In this instance, it was stack frame 3. Next to the name of my binary (myapp) are two similar hex numbers. These numbers correspond to the address of the command that is being called in that stack frame. Since frames 0 - 2 are Apple code, I can see the names of the messages. However, the crash was generated from ... somebody's ... iPhone. Since that person does not have my app's debugging symbols loaded on their phone (no one ever would) the crash report only shows the address of the message, not the name. So, my task is to figure out the line of my code that corresponds to address from the crash report. The command line tool 'atos' will help in this instance.
  • copied the address of stack frame 3
  • opened terminal, navigated to the directory
  • issued the following command
atos -o myapp.app/myapp -arch armv7 0x0000a728

This showed me my offending line:
-[MyClass myMessageThatDoesStuff:] (in myapp) (MyClass.m:327)

OK! I could see that the offending line was the message myMessageThatDoesStuff: in MyClass at line 327. I opened my code and had a look
I needed to see what message called myMessageThatDoesStuff:, so I copied the address from stack frame 4 and ran atos again.
atos -o myapp.app/myapp -arch armv7 0x0000a074
with the response of something like:
-[MyOtherClass myOtherMessage:didDoStuff:forUser:] (in myapp) (MyOtherClass.m:231)
So, I inspected MyOtherClass at line 231.

Eventually, this technique helped me to find my code that had released an object and then turned around and tried to use it. derp.

Sunday, October 17, 2010

Moving Media

I just bought two external USB drives to serve as a mirrored set. Setting up the RAID was easy using Disk Utility. Now I'm copying over iTunes, iPhoto, etc. Here's some handy instructions for iTunes: http://support.apple.com/kb/ht1449

Saturday, November 7, 2009

Edit Mac hosts file

If I don't write this down, I'll forget it. To edit the hosts file on a Mac, open Terminal and issue the following command:

sudo nano /private/etc/hosts

You can probably figure out the rest from there.

Friday, July 18, 2008

VNC for iPhone

Found a nice, free VNC tool for iPhone on AppStore. From AppStore, search for Mocha VNC Lite.

iSight always on

Here's the second Apple wierdness I experienced today. I noticed that the little green light next to the camera on my MacBook is always on. After poking around in Activity Monitor a little bit, nothing came to mind as an obvious program that could be using it. I had a thought that a malicious program was watching me. ;) Sorry, not a lot of excitement here unless you get off on dudes reading documentation and writing code. Anyway, that wasn't it. I seemed to fix it by "resetting the SMC". Here's the link from Apple that led me on my merry way.

iPhone won't charge

Here is the first of two wierdnesses I have experienced today. This first one involves my iPhone appearing to not recharge. I plugged it in to a wall jack last night. when I unplugged it, it showed that it was half full. I thought that was a bit odd, so when I got to work I plugged it in again. An hour or so later, it was still half full. So I thought maybe the wall plug thing isn't a good idea so I plugged it into my Mac. A little bit later, still half full. By this point I am getting worried. Oh noes! I have a faulty iPhone. Nah. I just restarted it and it showed that it was full.

Wednesday, July 16, 2008

iPhone Progress

I have had two evenings of great progress on the path to learning iPhone development. After spending several days pouring over a few sample projects from the iPhone Dev Center , particularly NavBar, I decided that I should start writing some code. So, from scratch, I managed to cobble together a little test that builds a TableView with multiple sections.




It's pretty meager; it doesn't really do anything useful. But it did a great deal to help me solidify a lot of concepts. Interface Builder makes a lot more sense, the implementation of MVC is really slick.

After showing this to Ben, he suggested that we put together a SubVersion repository for these little apps. So I downloaded a Mac client called SCPlugin from Tigris' site. It seems to work well. You Fireflies out there can keep up with our learning apps from our SVN server at /projects/iPhone/Playground. Though, after doing that, I poked around a little in XCode and see that the SVN integration isn't too bad there. Here are some pictures of the SVN stuff in XCode:



Friday, July 11, 2008

New iPhone Purchase

I am standing in line to purchase a new iPhone 3G. This is probably my last email from my Sprint Mogul. It has been a good phone on a great network. I am pretty sure that it knows that it's time has come early. I have never had a problem with it until about a week ago. Now it flakes out several times a day, and kicks off an alarm in the middle of the night that I CANNOT figure out how to turn off. The poor little guy is probably heartbroken. :(

The enthusiasm here is incredible. The line is wrapped nearly around the mall. Every Apple Store employee is here and giving high fives and all that. This feels more like waiting in line for the opening night of Star Wars (Episode I) than waiting in line for a little gadget.

Saturday, June 21, 2008

Firefly Macs

Today I met Ben at the Apple store to have a look at some computers. Ben wanted to see about getting one that we could use to "get our feet wet" with developing iPhone apps. We already have a great idea for our first one. When we met up at the store, he told me that he got approval to buy two for the company and that he and I were to be the first to use them. Within an hour or so of getting it home, the one I am using is all configured the way I like with Firefox, XCode, etc. ready to go. I have already taken to the gesture stuff on the touchpad. For instance, swiping with two fingers scrolls the current window). Thank you, Ben. I am very excited to start working on our first iPhone app.

Monday, June 16, 2008

One small step...

Here it is, the obligatory Hello World app. XCode is pretty cool. I feel comfortable with it after just a few minutes. I got a simple app together, got the iPhone Simulator to run, stepped through some code in the debugger and read some documentation. I still don't know what the frack I am doing, but it's a start.

Also, am currently reading the iPhone OS Programming Guide (in all of its two-sided printedness glory). That is probably a better starting doc than the Objective-C one.

Saturday, June 14, 2008

Objective C documentation

... so the iPhone adventure continues. I downloaded a bunch of PDF's from the iPhone Dev Center. I ran into a conundrum with what to do with them once I got them. I really am not the biggest fan of reading lots of text on a screen. When I want to learn a new language or technology, I usually buy a book or start a certification track. I have thusfar resisted the urge to buy some books. So on top of a new language, a new operating system and a new IDE, even the reading part of this journey is a departure from what I am used to. The printer we have at the house is an old HP DeskJet that really wouldn't be up to the task of printing hundreds of pages, I don't have access to a duplexing printer, and taking them to Kinko's is just too cost prohibitive. So I am lounging on the couch reading on the screen. Maybe this is my big chance to make the switch and save a few bucks and a few trees.

The first doc that I am trudging through is The Objective C Programming Language. It actually turns out to be a pretty good read and, despite the aforementioned difference in approach, I am getting a lot out of it. My first impression is that Objective C is much more similar to my experience than was my first forays into Ruby. There is a lot that I recognize as similar to C# and my meager experience with C++.

Sketches

Cool little article (http://arstechnica.com/journals/apple.ars/2008/06/11/ars-at-wwdc-exclusive-preview-of-iphone-app-sketches) about an iPhone app when iPhone apps wasn't cool allowed. Went to these guy's blog and found this article (http://latenitesoft.blogspot.com/2008/03/leopard-time-machine-issues-solved.html) about Time Machine that I would like to read later.

Friday, June 13, 2008

a new apple developer?

The other day I downloaded and watched the Apple WWDC keynote where Steve Jobs announced the new iPhone and the iPhone SDK. Wow!!! It is one of the coolest things I have seen in a while. I decided that I want to learn how to write applications for it. I have never written a line of code for the Mac. Heck, I just got my first Mac about 6 months ago. I'm still giddy that I can navigate around in it. It looks like iPhone applications (and Mac applications for that matter) are written in Objective-C. I am an intermediate C++ hack at best. Nonetheless, I am undaunted. So here begins a running record of my experience. I started by registering a user at the iPhone Developer Center. The first thing that struck me were all the Getting Started Videos. I downloaded all of them to iTunes and watched them. They seem to give a good overview of the significant design goals. I was kind of impressed that most of them seemed geared to developers that had OO experience, but no Mac development experience. Hey! That's me! While watching those, I downloaded the iPhone SDK and the XCode development tools from the Apple website. XCode is apparently the IDE for Mac and it's free. I am just now installing those. I think next I am going to read the some documentation they have for Objective-C and maybe dink around with some sample applications. Wish me luck!

Sunday, April 20, 2008

Front Row and iPhoto error

After importing a bunch of new photos into iPhoto, Front Row blew up when trying to view them. Found the fix here.

Monday, April 7, 2008

My Macintosh! Let me show you it!

Here is another post that I have been meaning to work on for ages. About two months ago, I bought my first Mac to use in my home theatre. It has turned out to be a really great way to share iTunes all over the house, have one big place for photos and it conveniently upconverts DVD's to 1080p (while I wait for just the right blu-ray player). I found a lot of people blogging about their happy experience using Mac Mini's as HTPC's (start here but also just Google {mac mini htpc}. So here is a stream of consciousness about my similar experience.

Gear (Phase 1)
I am starting off with a TV with HDMI inputs. I have not yet decided on a receiver. That does impact how I am plugging in the audio.
  • 2.0Ghz / 1GB RAM / 120GB hard drive Mac Mini - $800. I headed several recommendations to get the faster of the two current models because it does a little better with smooth DVD playing.
  • A DVI to HDMI cable ~ around $30 - It is probably cheaper to get an all in one cable instead of an HDMI cable and a DVI/HDMI adapter. It's a bummer that the Mac Mini doesn't have an HDMI out and the TV doesn't have a DVI in. So, I also got a 3.5mm male minijack to RCA stereo male cable - I actually already had this lying around the house. They're cheap, just get one at Best Buy or Radio Shack. This is the only way the TV will accept separate audio with an HDMI input. When I get a receiver, I will swap this out for a Toslink to mini cable to facilitate surround sound. Here's an example but you can find much cheaper ones.
  • A Bluetooth Apple keyboard - $80 and a Mighty Mouse - $70. I would guess that any Bluetooth mouse/keyboard will work. I also had a USB keyboard/mouse handy in case I would need them to get the computer up and running. It turns out they were unnecessary. When I fired up the Mac for the first time it found both items without a problem.
So, under $1000 for the whole getup. I also bought some other extras that frequently popped up on the blogs.

I got a 1TB LaCie external drive and an Elgato TV tuner. Later, I also bought an Apple AirPort Extreme, thinking it would fix a problem that I will discuss later.

I ended up taking the TV tuner back. It worked great, except that the TV listing software was an epic fail. I guess I just wasn't convinced that was the best DVR and decided to wait. I really would prefer to have one that is integrated into the computer instead of a TiVo or whatever. What am I going to do with 1TB anyway? However, I was dissatisfied with the fact that it had no way of using a cable-card, required a separate IR remote and had no way of consuming or recording HD or digital content that wasn't free over the air. I have yet to figure out a good solution. Maybe one doesn't exist. I have contemplated re-buying it. It's only $150. But at the moment, I have no DVR which, honestly, was a big part of the desirability of an HTPC in the first place.

The external hard drive is pretty good. The one I have is relatively quiet but it takes forever to spool up when it sleeps.

The buying experience
I spent several Saturday afternoons at the local Apple store poking around with the computer and various peripherals. I was planning on buying everything (even the TV, actually) through Amazon. However, it turned out that I would have had to pay tax on the Apple purchases through Amazon (is that still the case?), so since there was no real price advantage I decided to go ahead and buy the stuff from the Apple store. I have to say that I really, really enjoyed buying stuff there. The Apple store is a great retail experience. After talking to an employee about what I wanted, he went in the back and got all my loot. There are no cash-out lanes, so instead of standing in line, I got to peruse around and get more advice from other employees while I waited. He brought it all out to me and set it on a table in the middle of the store. He scanned everything with a handheld, put it all in a bag and then emailed my receipt to me. Stress free, fun, really cool. This is how I would like to buy jeans or furniture or ...

Cool Software
Front Row

Man, this thing alone just about sold me when I played with it at the store! It is even cooler on a 52" LCD, if you can imagine. I freely admit that I like shiny and new. It is the same interface that is used for the Apple TV. It is fun and easy for using on the couch with an Apple remote instead of getting out the mouse and keyboard.

VNC

It's like Remote Desktop for Windows. The VNC server is built in to the Mac. For a Windows client, I use TightVNC.

File Sharing
I had some difficulty using SMB. In fact, from a Windows laptop running Server 2003, it blue screened several times. Instead FTP seems to work MUCH better. I use FileZilla as the Windows client.

Things that could be better

Movie rentals on iTunes
I have now rented two movies on iTunes. The real big bummer is that only Apple TV can download HD content. You can only download "DVD Quality" content to a real computer. And then, once it has downloaded you have to watch it in iTunes. I really would prefer to watch it from Front Row like everything else. If you buy a TV show through iTunes, you can watch it right from Front Row. TV shows work pretty well. My only wish for TV shows is for Apple and NBC to work it out so I can download the new Battlestar Galactica episodes to iTunes. >:(

Wireless and Sleep
My single biggest gripe of my Mac is the known bug that wireless doesn't return after wake from sleep. I have found lots of complaints on this on the internet. Apple claimed that OSX 10.5.2 fixed this very problem. Nah. Still here. Basically, when it wakes from sleep it has the hardest time recovering the wireless network connection. I usually try turning AirPort on and off a good dozen times to get it to work. Real pain in the rear. My wife's MacBook runs the previous version (Tiger) and has never had a problem. There is a fun bit to this. You can get a glimpse of how Mac aficionados complain about bugs in Macs. Quite humorous. Google { wireless sleep leopard } and you will find things like this and this. I even went so far as to buy an AirPort Extreme (wireless router) thinking that the whole wireless thing would be fixed by an Apple-to-Apple communication. Nope. However, the AirPort includes a wireless print server which is bonus. It was a hassle to configure from a Windows client. I am used to Linksys products that are configurable through an HTTP interface. This one requires a thick client. But it is all the typical standards (802.11n, WPA2Personal, etc.) so once the AirPort Extreme was all setup, configuring the rest of the Windows and Mac clients (and a Windows Mobile client) was a breeze.

iPhoto
It's great if you pull photos off your camera on to the hard drive manually and then add them to iPhoto later. Pulling stuff directly into iPhoto and erasing them from the camera caused a whole evening of "fun" trying to recover the original pictures. I eventually dug the full size images out of a hidden folder ... { long story cut short }.

Finally
My Mac is pretty cool. It is a very reasonably priced and great performing HTPC. DVD's play very nicely. Front Row is lots of fun. There are a few hiccups, but nothing near enough to be of any real concern. I will eagerly post more as I learn more about my Mac. Actually, one of my next steps is to have a go at some Ruby development with it. To close, here's a picture of my wife enjoying the new toy a few days after we got it.