It was hack-a-thon days at work so I decided to try Flutter. I found a blank starter app then spent 10 Google Searches to about every two lines of code I actually wrote it seemed like. Flutter and Dart have both been evolving so much that a number of searches showed old information. At least most of the Stack Overflow stuff pointed you to the newer way of doing things.
For the past two years I have been doing Kotlin so I kept forgetting to add ; to the end of lines. Already know the IDE but I did not want to pollute Android Studio so I grabbed IntelliJ and set up under that. Configuration was pretty straight forward and since I am on a MacBook I could test both iOS and Android builds. Did all the work on Android emulator then tried it on iOS from time to time.
I used the Material look and I have zero if / then checks for Android or iOS. Small app so that does not prove a lot but for what I did I ran into no issues.
App has an image, read from assets, and 6 buttons with icons from the Icons package and text in a grid layout to go to other areas. One button shows an Alert Dialog. One goes to a screen with a ListView. The ListView is populated with items I read from a JSON file in the assets area.
I learned about Row, Column, Container, ListView, TextStyle, Expanded and all sorts of Widget properties. I have used a lot of layout managers over the years so I was able to get up to speed pretty quickly but I did a lot of searches to find what I needed and I refactored the layout code at least 6 times. Lots of indenting and easy to screw up a ( ) and [ ] matches or miss the ; at the end. The errors given by IDE generally pretty good.
Imported Intl, DateFormat and Decimal. Wrote converters for JSON as I have Date Time and Decimal needs due to Double having accuracy issues. Learned how to grab a file from assets. I did not mess with any network stuff as you need to login with OAuth first to get to any of our data and that seems like it would eat up both days.
Felt like I got a lot done in a day and a half. Very frustrating at first as getting anything simple to work took a lot of web searching and I went down so many wrong paths. First I was setting up the icon buttons as decorated columns then found I should be using FlatButton instead so I could get the actually tapped event and the tapped visual effects. Initial ListView code I found was very complicated but I found a simpler version and got it running quickly.
So am I a Flutter convert? No, I just wanted to see what it is all about. We use a number of 3rd parties for interaction with Credit Card readers and what not that probably would be a massive pain to deal with in Flutter. I was impressed at the speed of testing stuff in my small two screen app. The instant run is nice. Having an identical app on two platforms is sweet. Setting up images sucked as you have to manually add them into the YAML file. I just want all things in a directory to be there. On-line help is all over the place, some old, some new, some expecting you to know a lot especially when they talk about packages. They don't always mention what to add to your YAML so you do another search to find out that info.
Do I see some usages here? Kinda, like any app that appears to start out small you go "oh, I could do this simple app and get a free iOS version" but then you start adding more and more stuff then you hit some wall where you need something deeper in hardware and you are screwed.
Next areas would be doing actual REST calls, doing complicated UI work, SQLite interaction, lifecycle fun, shared preferences, animations, and basically being a real full featured app.
Glad I had time to play with it as was paid to do it. Time to save the code to Git and move back into my Kotlin reality. Worry is when I demo it this afternoon that the big bosses will think I found the holy grail of coding. Setting expectations is the key here.
Showing posts with label ios. Show all posts
Showing posts with label ios. Show all posts
Friday, April 19, 2019
Friday, September 21, 2018
Doing a little iOS work - Xcode is as bad as I remember
Our iOS programmer left. We have a new one starting next month. During the change over time I am doing some updates to the iOS code. Luckily before he left I got a pretty good overview of the current code so I am not running blind.
The fun is always Xcode. Never have liked that IDE much but it has been a few years since I did iOS work so I figured it has had time to improve. While Swift may have improved the areas I use daily to code have not. Git support is still barebones so I had to use SourceTree. SourceTree is nice and all but I shouldn't have to leave the IDE to interact with source control. I almost never touch SourceTree when doing work in Android Studio. I can easily create branches, merge things, remove branches, check history etc. right in the tool I am already using. I guess Apple really does not care about improving this area because as far as I can tell zero changes here.
Next up is searching. Yes Xcode gives you a number of ways to do it but it changes the mode a lot. If I look up usage of an enum, method or variable then the next time I search it is in that mode. I search for text a lot. Paying attention to the mode it is in because I right clicked on something in code but not on the search panel is frustrating.
Archiving stinks. Who thought this was a good word for building for release? Archive to me means put something out to pasture, you are done with it, store it way as it is old. But here is means build the latest for the store or TestFlight. I battled provisions / certificates / other crap for 45 minutes to get things out on TestFlight. Then I build the IAP for a user and that took a long time. I just started the export and let it run but dang was it slow.
There is also the wonderful fun of Interface Builder. So many tabs to get to settings. I will fully admit I like editing XML manually on Android. See all settings in one place, easy search and replaces as needed, easy to see cut and paste issues that I need to set up as styles. So much clicking in IB and you have to click on little [edit] links instead of on text. Might be powerful but it gets in your way when it comes to speed. Android gives me a choice, use visual editor if I want, manual if I don't. Yes IB generates XML but would you really manually edit what it creates? Last time I did a lot of iOS coding I skipped IB and did it all in code. Worked great for me as I am used to visualizing my layouts into manual XML creation. I used Masonry at the time so it was AutoLayout. Now that I use constraint layout on Android they are even closer.
Was able to pull off the critical changes need for next weeks release. I have never programmed in Swift but it is similar enough to Kotlin, which I have used for past 18 months, it was not too hard. Reactive Swift too boot but again the Kotlin syntax leads you that direction as well.
I came super close to downloading AppCode to use as a 30 day trial to get me over this hump until next dev appears. I may still do that if I have to spend much more time in the code. I have used AppCode at previous positions. Since it basically is same IDE as Android Studio I can hum right along using it and it works great with Git. Maybe I should just have work pony up for it anyway as I end up in the iOS code from time to time as it is. All my other Android tools are free so this can't be asking too much right?
The fun is always Xcode. Never have liked that IDE much but it has been a few years since I did iOS work so I figured it has had time to improve. While Swift may have improved the areas I use daily to code have not. Git support is still barebones so I had to use SourceTree. SourceTree is nice and all but I shouldn't have to leave the IDE to interact with source control. I almost never touch SourceTree when doing work in Android Studio. I can easily create branches, merge things, remove branches, check history etc. right in the tool I am already using. I guess Apple really does not care about improving this area because as far as I can tell zero changes here.
Next up is searching. Yes Xcode gives you a number of ways to do it but it changes the mode a lot. If I look up usage of an enum, method or variable then the next time I search it is in that mode. I search for text a lot. Paying attention to the mode it is in because I right clicked on something in code but not on the search panel is frustrating.
Archiving stinks. Who thought this was a good word for building for release? Archive to me means put something out to pasture, you are done with it, store it way as it is old. But here is means build the latest for the store or TestFlight. I battled provisions / certificates / other crap for 45 minutes to get things out on TestFlight. Then I build the IAP for a user and that took a long time. I just started the export and let it run but dang was it slow.
There is also the wonderful fun of Interface Builder. So many tabs to get to settings. I will fully admit I like editing XML manually on Android. See all settings in one place, easy search and replaces as needed, easy to see cut and paste issues that I need to set up as styles. So much clicking in IB and you have to click on little [edit] links instead of on text. Might be powerful but it gets in your way when it comes to speed. Android gives me a choice, use visual editor if I want, manual if I don't. Yes IB generates XML but would you really manually edit what it creates? Last time I did a lot of iOS coding I skipped IB and did it all in code. Worked great for me as I am used to visualizing my layouts into manual XML creation. I used Masonry at the time so it was AutoLayout. Now that I use constraint layout on Android they are even closer.
Was able to pull off the critical changes need for next weeks release. I have never programmed in Swift but it is similar enough to Kotlin, which I have used for past 18 months, it was not too hard. Reactive Swift too boot but again the Kotlin syntax leads you that direction as well.
I came super close to downloading AppCode to use as a 30 day trial to get me over this hump until next dev appears. I may still do that if I have to spend much more time in the code. I have used AppCode at previous positions. Since it basically is same IDE as Android Studio I can hum right along using it and it works great with Git. Maybe I should just have work pony up for it anyway as I end up in the iOS code from time to time as it is. All my other Android tools are free so this can't be asking too much right?
Thursday, May 14, 2015
I ripped out RestKit and replaced it NSURLSession and Mantle
When I started at my current job I knew I would be doing a lot of REST interaction with the server. I decided to use RestKit as I had seen it mentioned a number of times in various developer forums.
It worked for some time but I finally hit the breaking point and ripped it all out changing 265 to convert them to NSURLSession and Mantle. Was I insane? Pretty much as in the end it did not solve the problem I was originally attempting to address but I am happy with the change.
First off Mantle makes it much easier and cleaner to handle JSON. It is not as easy as GSON on the Android side but it is not too bad. That was a lot of my file conversions and I do find it easier to add a new JSON object due to a new REST call to the server. The one downfall is each of your JSON receiving objects has to be derived from a Mantle class. Objective C does not support multiple inheritance which could make this a very limiting factor for you.
The other area I am not too happy about with Mantle is it handles converting NSDictionary and NSArray to JSON. That means I get a big JSON string from REST and then I use NSJSONSerialization to convert it into a NSDictionary and then convert that via Mantle to Objective C objects. Waste of memory and processing to double convert things. Good thing the JSON data is reasonably small.
The other side was getting rid of RestKit calls. This helped the code a lot. I had one REST call manager class that tried to handle all the server calls with delegate callbacks. Now all the calls are inline where they are called in the code and that code has block processing to handle the results. This lets you see what is going on easier. Plus if it is a PUT call I only have to reference PUT in one line of code whereas I had to do that in three places when using RestKit. Setting up each call in RestKit took a boatload of error prone boilerplate code. I sure as heck don't miss that.
So why not go with AFNetworking? Seems to also be popular but in the end even AFNetworking is using NSURLSession in the end. Apple seems to put together a decent networking package learning from others. One less pod to include in my build and hopefully using the official Apple networking that appeared in iOS 7 will keep me in the safe zone.
On the Android side I am using Volley and GSON, both from Google but not part of the base Android SDK. Volley is very similar to NSURLSession which is good. GSON is easier to work with than Mantle in there is less boilerplate code. If your variable names match the property names in the JSON you get from the server there really is no boilerplate at all. If they don't match a simple annotation gets them to sync up.
So what was the original issue I was attempting to fix? I want to have two type of NSURLSessions going in the code, one to do the normal user interaction processing - they tap something, I make a server request, I get server result and I show new data in the current view or in a new view. The second was to be a background session for uploading video via Amazon Web Services.
I am using AWS but I am using the straight API from them. Yes, there is sample upload in the background code out there and it works when you don't have the other NSURLSession doing other work which really stinks. I want the user to be able to start a video upload and have it run in the background until complete even if they leave my app or turn off the phone screen. Works like a champ on the Android side where I set up a very basic service.
I realize Apple really does not want you do to anything in the background. They trust no one. They do have a new thing that lets you get maybe 10 minutes of time to do some background work. That is one of the things NSURLSession is set to allow. But I just can't get it to work. It will start, send up some % of the video then restart at 0% and do that over and over again. On the simulator, which does not run like a real device, it can get the whole video uploaded never triggering the restart you see on the iPhone or iPad. I have posted a message on Stack Overflow describing this issue but no answers.
I really wish Amazon would handle this for you in their API. Seems like background uploading would be a really common thing for a programmer to want to do with them. Maybe Apple could handle it in their API as well but I doubt that as they are anti-background as it is.
It worked for some time but I finally hit the breaking point and ripped it all out changing 265 to convert them to NSURLSession and Mantle. Was I insane? Pretty much as in the end it did not solve the problem I was originally attempting to address but I am happy with the change.
First off Mantle makes it much easier and cleaner to handle JSON. It is not as easy as GSON on the Android side but it is not too bad. That was a lot of my file conversions and I do find it easier to add a new JSON object due to a new REST call to the server. The one downfall is each of your JSON receiving objects has to be derived from a Mantle class. Objective C does not support multiple inheritance which could make this a very limiting factor for you.
The other area I am not too happy about with Mantle is it handles converting NSDictionary and NSArray to JSON. That means I get a big JSON string from REST and then I use NSJSONSerialization to convert it into a NSDictionary and then convert that via Mantle to Objective C objects. Waste of memory and processing to double convert things. Good thing the JSON data is reasonably small.
The other side was getting rid of RestKit calls. This helped the code a lot. I had one REST call manager class that tried to handle all the server calls with delegate callbacks. Now all the calls are inline where they are called in the code and that code has block processing to handle the results. This lets you see what is going on easier. Plus if it is a PUT call I only have to reference PUT in one line of code whereas I had to do that in three places when using RestKit. Setting up each call in RestKit took a boatload of error prone boilerplate code. I sure as heck don't miss that.
So why not go with AFNetworking? Seems to also be popular but in the end even AFNetworking is using NSURLSession in the end. Apple seems to put together a decent networking package learning from others. One less pod to include in my build and hopefully using the official Apple networking that appeared in iOS 7 will keep me in the safe zone.
On the Android side I am using Volley and GSON, both from Google but not part of the base Android SDK. Volley is very similar to NSURLSession which is good. GSON is easier to work with than Mantle in there is less boilerplate code. If your variable names match the property names in the JSON you get from the server there really is no boilerplate at all. If they don't match a simple annotation gets them to sync up.
So what was the original issue I was attempting to fix? I want to have two type of NSURLSessions going in the code, one to do the normal user interaction processing - they tap something, I make a server request, I get server result and I show new data in the current view or in a new view. The second was to be a background session for uploading video via Amazon Web Services.
I am using AWS but I am using the straight API from them. Yes, there is sample upload in the background code out there and it works when you don't have the other NSURLSession doing other work which really stinks. I want the user to be able to start a video upload and have it run in the background until complete even if they leave my app or turn off the phone screen. Works like a champ on the Android side where I set up a very basic service.
I realize Apple really does not want you do to anything in the background. They trust no one. They do have a new thing that lets you get maybe 10 minutes of time to do some background work. That is one of the things NSURLSession is set to allow. But I just can't get it to work. It will start, send up some % of the video then restart at 0% and do that over and over again. On the simulator, which does not run like a real device, it can get the whole video uploaded never triggering the restart you see on the iPhone or iPad. I have posted a message on Stack Overflow describing this issue but no answers.
I really wish Amazon would handle this for you in their API. Seems like background uploading would be a really common thing for a programmer to want to do with them. Maybe Apple could handle it in their API as well but I doubt that as they are anti-background as it is.
Tuesday, March 3, 2015
iOS battling 3rd party tools
I have been battling various items in iOS over that past week and it is getting really frustrating.
First up I really wanted a dialog with some text entry and a few buttons. They pulled the "custom view" part out post iOS 6 so I found a few GitHub repositories that should solve the problem. First once just did not pan out and the UIView just did not look right. Second one appeared to work OK at first but then it did not play well in iOS 8 in landscape.
Apple decided to change the way you get back height and width of the screen in iOS 8. Previously you always got height and width as if you were in portrait mode. Now they give it back for the current screen orientation. Huge change for programmers. People had height / width swapping code to handle this and you still have to do that for iOS 7 and older.
I fixed the code so landscape worked for iOS 8 on the simulator. Once I ran it on a real device things went to crap again. Extra things being painted and the keyboard popping up really screwed things. Lesson learned - iOS really does not like this sort of popup with editing.
Gut things yet again and go with a UIPopoverController on the iPad and navigation to a UIViewController on the iPhone. Can't say I am super happy with the iPhone version but it works and popping up the keyboard does not screw anything up.
Next up was the menu. iOS 7 has a bug. If you have too many items in a UIActionSheet on an iPhone you can't tap the top most item if it happens to cover the main navigation area. Works fine on iOS 8 but broken on iOS 7. UIActionSheet expects just a few items.
So I found a popup menu that allows up to 9 items per screen and you can swipe to scroll and see more. It is call btSimplePopUP. Now I should have known that someone using two menus - btSimplePopUp and btSimplePopUP - in the same directory structure was going to be iffy. The demo screens look nice though. I put in the code and I get the menu to appear but with a black background. What? It is not blurring out my UIViews, just blanking them out. Then I look for known issues and it turns out the control does not work in landscape which is a requirement for me.
Punt that control. I am now looking at KxMenu which seems to be working in portrait and landscape and takes up a lot less screen space than UIActionSheet. Hopefully it will be the solution.
Lots of GitHub projects lose support. iOS 8 was a big change and it takes some recoding especially with custom controls due to the changes Apple made. Stinks people don't have the time to keep things updated. Even worse when I waste the time trying to get them to work. I need to start looking at the known issues first. Anytime it does not support landscape I am not going to use it. Hopefully they also list if there is iOS 8 support issues as well.
First up I really wanted a dialog with some text entry and a few buttons. They pulled the "custom view" part out post iOS 6 so I found a few GitHub repositories that should solve the problem. First once just did not pan out and the UIView just did not look right. Second one appeared to work OK at first but then it did not play well in iOS 8 in landscape.
Apple decided to change the way you get back height and width of the screen in iOS 8. Previously you always got height and width as if you were in portrait mode. Now they give it back for the current screen orientation. Huge change for programmers. People had height / width swapping code to handle this and you still have to do that for iOS 7 and older.
I fixed the code so landscape worked for iOS 8 on the simulator. Once I ran it on a real device things went to crap again. Extra things being painted and the keyboard popping up really screwed things. Lesson learned - iOS really does not like this sort of popup with editing.
Gut things yet again and go with a UIPopoverController on the iPad and navigation to a UIViewController on the iPhone. Can't say I am super happy with the iPhone version but it works and popping up the keyboard does not screw anything up.
Next up was the menu. iOS 7 has a bug. If you have too many items in a UIActionSheet on an iPhone you can't tap the top most item if it happens to cover the main navigation area. Works fine on iOS 8 but broken on iOS 7. UIActionSheet expects just a few items.
So I found a popup menu that allows up to 9 items per screen and you can swipe to scroll and see more. It is call btSimplePopUP. Now I should have known that someone using two menus - btSimplePopUp and btSimplePopUP - in the same directory structure was going to be iffy. The demo screens look nice though. I put in the code and I get the menu to appear but with a black background. What? It is not blurring out my UIViews, just blanking them out. Then I look for known issues and it turns out the control does not work in landscape which is a requirement for me.
Punt that control. I am now looking at KxMenu which seems to be working in portrait and landscape and takes up a lot less screen space than UIActionSheet. Hopefully it will be the solution.
Lots of GitHub projects lose support. iOS 8 was a big change and it takes some recoding especially with custom controls due to the changes Apple made. Stinks people don't have the time to keep things updated. Even worse when I waste the time trying to get them to work. I need to start looking at the known issues first. Anytime it does not support landscape I am not going to use it. Hopefully they also list if there is iOS 8 support issues as well.
Tuesday, January 13, 2015
Why I have given up on Interface Builder and Story Boards
I just ran into another case where Interface Builder did not allow me to do what I wanted to do and I finally just gave up and pulled everything but the first view controller from the storyboard. This is the story of how I got to this point.
My first iOS app was one of "finish this". Another developer who was no longer with the company had developed the app. I had the job of finishing the app and converting it to Android. I already knew Java and had written an Android app that was in the store. The iOS version used NIBs as this was back in the iOS 4 timeframe.
I continued down the NIB path and converted the app to be universal with special code for iPad layouts. There was special cases for landscape vs. portrait on one of the screens as well. Seemed to work OK but it was a fairly straightforward app.
I worked only on Android apps for a some time before my next position where I did both iOS and Android work again.
The next iOS app I worked on was written by another developer and he used storyboards. Still using the old style layouts with pixel perfect positioning. I kept the storyboards in place seeing some of the advantages of using them and added the iPad storyboard side of things. I liked how much easier it was to get things going, used segues and like the idea of seeing the program flow in a visual designer. Took quite a bit of web research to understand how it all tied together and a lot of clicking on tabs in IB to find all the secret nooks and crannies where you could set things.
I did a couple of other apps for the company that I got to write from scratch. I used the new found storyboards for them as well. Sadly none of these apps went to market as they never finished the server side of the work. Lots of pretty apps to demo at sales meetings but they were just demos.
For my current job I am again getting to write the app from scratch. I am doing the same with the Android side of things. I started out using storyboards and it was time to get into autolayout. Since I have been doing Android work and I have also done a lot of Java desktop work I have a solid understanding of doing layouts that scale.
I dove into autolayout and found it rather confusing. It appears to me to be written in the land of academia instead of the land of real world programming. One layout to rule them all no matter how you have to force things into it. Very verbose in one code only format and very terse in the other. If you do it in Interface Builder then you just have to know how to do things. Click here, Ctrl + Click here, set up constraints, delete them, set them up again, have them conflict, pull hair. Always something wrong and it get really bad when you have a complex layout. For a company that prides itself in UI and UX I must say IB is not a good reflection of that goal.
After fighting it and working with other iOS devs over chat I found Masonry and switched to that. Yes, it is code and not WYSIWYG but I could create complex layouts and have them work. I could do different layouts for iPad and iPhone and follow them logically. I still have storyboard layouts but most of them were empty as the code created the real layout. I was just using them for segues and to see program flow. That was until yesterday.
There I was back in Interface Builder. I just wanted a UITableView to move down one level, to have another UIView as its parent. IB fought me tooth and nail. I could and a UIView to the list but it would not show up under the UIViewController no matter how I dragged and dropped and clicked. I then said screw it and deleted that entire view controller and created a new one where I could re-add the UITableView but then all my segue links broke and all the IBOutlets into the code broke and I would have to do it again for the iPad storyboard and all the work went on and on. Plus Xcode crashed more than once while I was in it doing simple things.
Storyboards end up sucking pretty quickly. There is not enough screen room to see your iPad layouts. You get to see one scene at a time. Sure you can zoom out but the minute you edit something it zooms back in. Just opening a storyboard seems to trigger Xcode into thinking there was a change. If you look in the XML you will see it changed x = 4.0 to x = 3.999999999 or something just as stupid. Everything I did I had to do twice, once for iPhone and once for iPad. The IDE does not tell you if you forget to wire up a UIView to an IBOutlet. Objective C does not care if you send messages to a nil object. Moving a UIView can screw up the whole layout quickly. You can't see all the constraints in one place, you have to look in each level of the layout to see them and they are terse and unrelated to each other. When you try to Ctrl+Drag a UIView into the code you hardly can see anything else on screen.
I gave up. IB was fighting me not helping me. I converted all the code to Masonry and I was able to control that layout exactly. I had to move all the segue processing in code as well. It took me all day to get my code back to where it was before but now I am in control of all of it.
I don't have to do things twice. iPad and iPhone both work from one code base. I may have some if statements in code to tweak layout for iPad but I don't have to double layout it out in a crappy UI editor called IB and I don't have to double connect every UIView to a IBOutlet.
I can move a control around in my layout by changing a few lines of code instead clicking a bunch of times in IB and having it get pissed and redo other constraints.
I can name my controls so when I do get log messages about my layout being screwy I know exactly which UILabel it is mad about instead of guessing.
Another issue that bit me, I fixed, that bit me again and I fixed the right way arose. I needed a second line for the title area on iPhone. iPad has enough horizontal space to not need this. I was using the navigation prompt property which adds a second line of text to the title area. On Android I could use title / subtitle to do same thing but on Android this requires no extra vertical space.
How did this bite me twice? A number of months ago I wanted to add a UILabel above my UITableView but I could not due to same issues that I just covered, I could not get the UITableView hosted by another UIView. Thus I used the prompt property. It worked OK. After the conversion away from storyboards everything in this UIViewController aligned just fine the first time I displayed it but when I tapped a table row and moved to the detail screen then back to the table screen setting the prompt caused the navigation area to grow and it covered up part of my table. Rotating to landscape and back would fix it. I tried all sorts of relayout, needs display, calculation of offsets etc. and could not get it to work. Why autolayout would not stay in sync is beyond me but I got sick of fighting that.
Then I remembered what I originally wanted to do - put a UILabel above the UITableView on iPhone only. Now I am in control as I am using Masonry. Put the UILabel in place and changed all code references from prompt = to promptLabel.text = and I have a working layout the way I originally wanted.
I have no plans use prompt again due to it screwing up layouts and I will not be using storyboards or Interface Builder either. They just are not stable and cause more trouble than they are worth. I also do most of my work in AppCode instead of Xcode as AppCode does a much better job in a lot of areas. Better editor, much better refactoring, GIT actually works properly and it is stable. I have had it crash on me once in the two plus years I have been using it.
The other added benefit - I can take my code and drop it in another project and it will work. I have no dependencies on copying the layouts twice and having to manually reconnect every single freaking UIView to an IBOutlet. My code is self contained. It lays itself out and knows how to talk to all of its controls.
Goodbye IB and storyboards. I don't miss you.
My first iOS app was one of "finish this". Another developer who was no longer with the company had developed the app. I had the job of finishing the app and converting it to Android. I already knew Java and had written an Android app that was in the store. The iOS version used NIBs as this was back in the iOS 4 timeframe.
I continued down the NIB path and converted the app to be universal with special code for iPad layouts. There was special cases for landscape vs. portrait on one of the screens as well. Seemed to work OK but it was a fairly straightforward app.
I worked only on Android apps for a some time before my next position where I did both iOS and Android work again.
The next iOS app I worked on was written by another developer and he used storyboards. Still using the old style layouts with pixel perfect positioning. I kept the storyboards in place seeing some of the advantages of using them and added the iPad storyboard side of things. I liked how much easier it was to get things going, used segues and like the idea of seeing the program flow in a visual designer. Took quite a bit of web research to understand how it all tied together and a lot of clicking on tabs in IB to find all the secret nooks and crannies where you could set things.
I did a couple of other apps for the company that I got to write from scratch. I used the new found storyboards for them as well. Sadly none of these apps went to market as they never finished the server side of the work. Lots of pretty apps to demo at sales meetings but they were just demos.
For my current job I am again getting to write the app from scratch. I am doing the same with the Android side of things. I started out using storyboards and it was time to get into autolayout. Since I have been doing Android work and I have also done a lot of Java desktop work I have a solid understanding of doing layouts that scale.
I dove into autolayout and found it rather confusing. It appears to me to be written in the land of academia instead of the land of real world programming. One layout to rule them all no matter how you have to force things into it. Very verbose in one code only format and very terse in the other. If you do it in Interface Builder then you just have to know how to do things. Click here, Ctrl + Click here, set up constraints, delete them, set them up again, have them conflict, pull hair. Always something wrong and it get really bad when you have a complex layout. For a company that prides itself in UI and UX I must say IB is not a good reflection of that goal.
After fighting it and working with other iOS devs over chat I found Masonry and switched to that. Yes, it is code and not WYSIWYG but I could create complex layouts and have them work. I could do different layouts for iPad and iPhone and follow them logically. I still have storyboard layouts but most of them were empty as the code created the real layout. I was just using them for segues and to see program flow. That was until yesterday.
There I was back in Interface Builder. I just wanted a UITableView to move down one level, to have another UIView as its parent. IB fought me tooth and nail. I could and a UIView to the list but it would not show up under the UIViewController no matter how I dragged and dropped and clicked. I then said screw it and deleted that entire view controller and created a new one where I could re-add the UITableView but then all my segue links broke and all the IBOutlets into the code broke and I would have to do it again for the iPad storyboard and all the work went on and on. Plus Xcode crashed more than once while I was in it doing simple things.
Storyboards end up sucking pretty quickly. There is not enough screen room to see your iPad layouts. You get to see one scene at a time. Sure you can zoom out but the minute you edit something it zooms back in. Just opening a storyboard seems to trigger Xcode into thinking there was a change. If you look in the XML you will see it changed x = 4.0 to x = 3.999999999 or something just as stupid. Everything I did I had to do twice, once for iPhone and once for iPad. The IDE does not tell you if you forget to wire up a UIView to an IBOutlet. Objective C does not care if you send messages to a nil object. Moving a UIView can screw up the whole layout quickly. You can't see all the constraints in one place, you have to look in each level of the layout to see them and they are terse and unrelated to each other. When you try to Ctrl+Drag a UIView into the code you hardly can see anything else on screen.
I gave up. IB was fighting me not helping me. I converted all the code to Masonry and I was able to control that layout exactly. I had to move all the segue processing in code as well. It took me all day to get my code back to where it was before but now I am in control of all of it.
I don't have to do things twice. iPad and iPhone both work from one code base. I may have some if statements in code to tweak layout for iPad but I don't have to double layout it out in a crappy UI editor called IB and I don't have to double connect every UIView to a IBOutlet.
I can move a control around in my layout by changing a few lines of code instead clicking a bunch of times in IB and having it get pissed and redo other constraints.
I can name my controls so when I do get log messages about my layout being screwy I know exactly which UILabel it is mad about instead of guessing.
Another issue that bit me, I fixed, that bit me again and I fixed the right way arose. I needed a second line for the title area on iPhone. iPad has enough horizontal space to not need this. I was using the navigation prompt property which adds a second line of text to the title area. On Android I could use title / subtitle to do same thing but on Android this requires no extra vertical space.
How did this bite me twice? A number of months ago I wanted to add a UILabel above my UITableView but I could not due to same issues that I just covered, I could not get the UITableView hosted by another UIView. Thus I used the prompt property. It worked OK. After the conversion away from storyboards everything in this UIViewController aligned just fine the first time I displayed it but when I tapped a table row and moved to the detail screen then back to the table screen setting the prompt caused the navigation area to grow and it covered up part of my table. Rotating to landscape and back would fix it. I tried all sorts of relayout, needs display, calculation of offsets etc. and could not get it to work. Why autolayout would not stay in sync is beyond me but I got sick of fighting that.
Then I remembered what I originally wanted to do - put a UILabel above the UITableView on iPhone only. Now I am in control as I am using Masonry. Put the UILabel in place and changed all code references from prompt = to promptLabel.text = and I have a working layout the way I originally wanted.
I have no plans use prompt again due to it screwing up layouts and I will not be using storyboards or Interface Builder either. They just are not stable and cause more trouble than they are worth. I also do most of my work in AppCode instead of Xcode as AppCode does a much better job in a lot of areas. Better editor, much better refactoring, GIT actually works properly and it is stable. I have had it crash on me once in the two plus years I have been using it.
The other added benefit - I can take my code and drop it in another project and it will work. I have no dependencies on copying the layouts twice and having to manually reconnect every single freaking UIView to an IBOutlet. My code is self contained. It lays itself out and knows how to talk to all of its controls.
Goodbye IB and storyboards. I don't miss you.
Labels:
Apple,
interface builder,
ios,
masonry,
storyboard
Friday, August 29, 2014
Switched to autolayout via Masonry
I have known for some time that I needed to start using autolayout for my iOS development. My current app is universal so I was doing things twice already in Interface Builder which was getting to be a real pain. Add the control, drag and drop the IBOutlet connections and don't forget to do it on the other side.
I tried to use autolayout in Interface Builder and finally got my fairly simple login screen to work but I cussed at it the whole time. Move a control, have IB tell you the constraints and form are out of sync, correct it and repeat. If you move a control that was used as a reference anchor for other controls then it got really lost. You end up manually deleting constraints that show up either below the control you are moving or maybe at the root view. Just way to painful and error prone.
Here is where https://github.com/Masonry/Masonry comes into play. I have used a number of layout managers in the past including standard Java layouts, MigLayout for Java and the Android XML layouts. Masonry is similar to each of them in a number of areas.
A new layout with about 35 controls was the tipping point. No way I was going to do that after all the venom I spewed at IB doing the login view with only 7 controls. I got the new layout working pretty quickly in Masonry then I went back and ripped the login from IB and did it in Masonry where I can easily see the exact constraints and view relationships.
I attempting to use the Apple flavor of programmatically doing autolayout but I found it to be very verbose and nearly as confusing as IB. The other shorter syntax messed with my mind also. Masonry seemed to go right down the middle.
Not a huge fan of checking in the code for iPhone vs. iPad but for a universal app where you want special layouts that is what you get to do. Not sure what will happen when the new iPhone 6 comes into play.
I am now skipping story boards and all their headaches and just doing my layouts in code. This also means is a new developer was to come on board we would not be walking on top of each other when we change a layout which stinks with storyboards and version control. That developer would get to learn Masonry but it is reasonable straight forward. I still run into some odd layout issues that send me scrambling to stack overflow but in general it has been pretty smooth.
UIScrollView gave me the most fun but once I figured out how to anchor the scroll view to the main view then anchor child views of the scroll view to the scroll view it all worked out.
The error messages given by autolayout are not super helpful. Some trial and error is involved but I don't run into errors very often anymore.
I tried to use autolayout in Interface Builder and finally got my fairly simple login screen to work but I cussed at it the whole time. Move a control, have IB tell you the constraints and form are out of sync, correct it and repeat. If you move a control that was used as a reference anchor for other controls then it got really lost. You end up manually deleting constraints that show up either below the control you are moving or maybe at the root view. Just way to painful and error prone.
Here is where https://github.com/Masonry/Masonry comes into play. I have used a number of layout managers in the past including standard Java layouts, MigLayout for Java and the Android XML layouts. Masonry is similar to each of them in a number of areas.
A new layout with about 35 controls was the tipping point. No way I was going to do that after all the venom I spewed at IB doing the login view with only 7 controls. I got the new layout working pretty quickly in Masonry then I went back and ripped the login from IB and did it in Masonry where I can easily see the exact constraints and view relationships.
Not a huge fan of checking in the code for iPhone vs. iPad but for a universal app where you want special layouts that is what you get to do. Not sure what will happen when the new iPhone 6 comes into play.
I am now skipping story boards and all their headaches and just doing my layouts in code. This also means is a new developer was to come on board we would not be walking on top of each other when we change a layout which stinks with storyboards and version control. That developer would get to learn Masonry but it is reasonable straight forward. I still run into some odd layout issues that send me scrambling to stack overflow but in general it has been pretty smooth.
UIScrollView gave me the most fun but once I figured out how to anchor the scroll view to the main view then anchor child views of the scroll view to the scroll view it all worked out.
The error messages given by autolayout are not super helpful. Some trial and error is involved but I don't run into errors very often anymore.
Monday, July 14, 2014
When do you learn a new library?
When do you take the time to learn a new library? I decided now was as good a time as any since I was at a new job and working on a new application. In the past I have used straight JSON parsing and hand written HTTP code. This time I decide to see what RestKit had to offer for both areas and I am happy I did that.
It can be very hard to retrofit a new library into old code. The design most likely does not follow the new pattern. No one wants to start from scratch when an existing product is already working. Kind of a shame because a lot of the time doing that can really make things work a lot better and make it easier to catch odd exceptions.
Per usual I got the Android side up and running pretty quickly. I did use the GSON library, which I have used in the past, but I used it in a deeper way. I set up the objects with the correct annotations and I let the library create my objects from the HTML body of the response. Worked like a champ. I implemented loaders to pull in the data and images for everything to happen on a background thread.
Next up was the iOS version. I found a lot of RestKit information on the web so I figured I would give it a shot. Not only does it handle the HTML / JSON request / responses but it also deals with JSON to object mapping. It took a bit more work to get that going though. You have to return object mappings instead of doing simple annotations. Once I had it figured out it worked very well. Some trial and error as I made the request over and over to the server to see what else I screwed up in the mapping. The JSON objects I am parsing go 6 levels deep. I did not write the server side so I am not in control of that aspect.
The image side was a different story at least when it comes to requesting a lot of images via queue in a background thread. There is a lot of documentation about the older .10 version of RestKit but less for the newer .20 code base. I fumbled around with things for a bit then found the SDWebImage library which did exactly what I needed in very few lines of code.
I am using CocoaPods for all my iOS work along with AppCode for the IDE. Yes, I have to switch back to Xcode from time to time as I can't find ways of doing things such as adding a Font to the project. This is not a super straight forward thing in Xcode either. I really want AppCode to do everything. I have been doing my Storyboard work in AppCode. Took a little bit of time to figure out where to drag from to get the IBOutlet connections to work. Xcode is confusing in this area too, nothing leads you down the path, you need to know to hold down the right keys and drag things and drop them on the right area. They improved this with Xcode 5 where you drop directly in the code but boy does the screen get cluttered when you try and have an iPad Storyboard open with code too.
Working with iPad Storyboards is a pain in both products. The screens are big and even though I am running the IDE on a 24" monitor there still is not enough space. I guess I need to have the IDE span both of my monitors as anytime you need to set up a segue between two screens you just don't have the space to do it. Even running the simulator on a 24" monitor for an iPad Retina at 50% leaves scrollbars in place. This outright sucks. I use GenyMotion for my Android work and I am able to easily scale that window to fit on screen.
It can be very hard to retrofit a new library into old code. The design most likely does not follow the new pattern. No one wants to start from scratch when an existing product is already working. Kind of a shame because a lot of the time doing that can really make things work a lot better and make it easier to catch odd exceptions.
Per usual I got the Android side up and running pretty quickly. I did use the GSON library, which I have used in the past, but I used it in a deeper way. I set up the objects with the correct annotations and I let the library create my objects from the HTML body of the response. Worked like a champ. I implemented loaders to pull in the data and images for everything to happen on a background thread.
Next up was the iOS version. I found a lot of RestKit information on the web so I figured I would give it a shot. Not only does it handle the HTML / JSON request / responses but it also deals with JSON to object mapping. It took a bit more work to get that going though. You have to return object mappings instead of doing simple annotations. Once I had it figured out it worked very well. Some trial and error as I made the request over and over to the server to see what else I screwed up in the mapping. The JSON objects I am parsing go 6 levels deep. I did not write the server side so I am not in control of that aspect.
The image side was a different story at least when it comes to requesting a lot of images via queue in a background thread. There is a lot of documentation about the older .10 version of RestKit but less for the newer .20 code base. I fumbled around with things for a bit then found the SDWebImage library which did exactly what I needed in very few lines of code.
I am using CocoaPods for all my iOS work along with AppCode for the IDE. Yes, I have to switch back to Xcode from time to time as I can't find ways of doing things such as adding a Font to the project. This is not a super straight forward thing in Xcode either. I really want AppCode to do everything. I have been doing my Storyboard work in AppCode. Took a little bit of time to figure out where to drag from to get the IBOutlet connections to work. Xcode is confusing in this area too, nothing leads you down the path, you need to know to hold down the right keys and drag things and drop them on the right area. They improved this with Xcode 5 where you drop directly in the code but boy does the screen get cluttered when you try and have an iPad Storyboard open with code too.
Working with iPad Storyboards is a pain in both products. The screens are big and even though I am running the IDE on a 24" monitor there still is not enough space. I guess I need to have the IDE span both of my monitors as anytime you need to set up a segue between two screens you just don't have the space to do it. Even running the simulator on a 24" monitor for an iPad Retina at 50% leaves scrollbars in place. This outright sucks. I use GenyMotion for my Android work and I am able to easily scale that window to fit on screen.
Tuesday, June 10, 2014
Back to mobile dev
While my stint doing AngularJS work was interesting I am back into full time mobile work. Man I missed it and I am happy to be back into it.
Of course you are always surprised about how much you forget when you spend time away from something. I get to do both iOS and Android again. I started on the Android side first as I have always been more comfortable in Java than Objective C. I have the main login, logout and initial REST calls working under Android. Today I was working from home on the MacBook so I started to tackle the iOS side of things.
First I wanted to make sure I did autolayout from the start. Apple is pushing it and there are signs that Apple will release a different sized phone and maybe side by side program running on iPads. This means your code should be able to run as resolution independent as possible. Something you do almost by default on Android.
Autolayout is a bit weird but I got the login screen to work without any code for both portrait and landscape in the iPad storyboard. I started experimenting with AppCode 3.0 but ran into issues just getting my images into the xcassets area so I switched back to Xcode for this round of fun. I will switch back to AppCode once the UI is in place and I am doing gut level coding.
I had to create the various icons and launch screen images. I had large sized assets so I used Seashore for simple scaling. It annoys me that Mac OS does not bring an app to the front when you hover over it like Windows does. I wanted to DnD the images from Finder to Xcode. Luckily I am running a dual screen setup so I just moved Finder to the other screen and did it that way.
I copied over some other code and utility files I use and got the basics of the login screen in place. Now I get to decide which JSON library to use. I might just go with NSJSONSerialization this round. I have used YAJL in the past but I did that because I needed to stream things as the data was too big to hold in memory multiple times. Right now I do have that issue. I did not need to stream on the Android side, I am using GSON over there. I do like GSON parsing right into my natural object format where NSJSONSerialization just does a generic dictionary. Makes method name traversal impossible. The objects are rather deep for the JSON I am getting back so I need to find a decent way to get to the info I need. All the REST calls are done via C# and IIS so none of it is really optimized for Java or Objective C consumption but it is JSON which I find easier to deal with than XML.
I will need to all pull to refresh and navigation menu support too. Guess I need to get my head back into Objective C and review the list of CocoaPods I used in the past.
Since all the news about Swift as been in the news as of late I have started to sniff around. To me it looks like a nice step in new direction. I like they syntax having never been a big fan of [ ] []]]]]] [[[][][]]] all over in Objective C. Swift looks JavaScript like. Don't think I care for the .. vs. ... for the loop construct where on does inclusive start / end index and the other does start / end - 1. I would rather have a more distinct syntax between the two.
Sadly I don't have current access to Xcode 6 so I am not playing with that. From what I have read neither Swift nor Xcode 6 is ready for primetime meaning it is best for me to concentrate on the old Objective C via Xcode 5 and AppCode for now. Documentation is also sparse. I hope they hammer out the issues quickly as I would like to move away from Objective C sooner than later.
I have picked up a lot of info on the Android side again too. I have done JSON work there before but again I forgot a bunch of it having not messed with it in nearly a year. Good thing Google works most days.
Thursday, September 5, 2013
AAAARRGGGG iOS layouts stink!
I hate iOS layout management. Yes, everyone loved it when you knew the iPhone had this one resolution and you could perfectly layout everything. All phones were held in portrait only mode. Even the auto code generator blocked landscape by default. We knew what you had and how you would use it so just shut up. All Apple devs told Android devs they were hosed with their stupid layout managers without true WYSIWYG editing. Na-na-na-na-boo-boo.
This meant if you wanted to support landscape you added code to move things around and resize them during orientation changes. You could still use IB to see that pristine portrait view. Then came the iPad which was used in landscape a lot. Just do IB in that mode.
Well IB sucks. Adding storyboards just allowed it to suck in some new ways. Sure you can tie you portrait screens together and you can do separate iPad and iPhone screens but you have to manually tie all the controls back to your source code with crazy Ctrl + Click drag and drop if you can get the right source file to appear in a squished down window below the stupid layout that is way too damn big for iPad screens that wants to constantly scroll and resize every freaking time you click on it!
You are an idiot - use auto layout. If you don't then you are hosed. But Apple did not backport that, you had to wait until most users were on iOS 6. Google backports, Apple does not. Apple is a jerk in this area. iOS 6 seems like a safe enough target at this point.
Auto layout has a new set of issues. IB really blows here. It has to have everything in perfect order even though when you are creating the layout you can't get it in perfect order until the layout is fully loaded with all the controls. They IB rewrites the damn file over and over. You lose the battle every single time wasting a huge amount of effort.
So screw IB, it has been screwing you. Besides if you want a team working on things they can't all have the storyboard open because version controls DIFF is nearly impossible. It is a SNAFU. Time to write it all in code and skip everything related to IB.
You have a couple of choices. Use the auto layout weird ASCII stuff, which is just ugly to read, or use NSLayoutConstraints manually. I think I am going NSLayoutConstraints. If I am getting no WYSIWYG support I might as well take full controls. That ASCII stuff is too bizarre. Honestly this all feels like I am moving back into the land of GridBagLayout in Java.
GridBagLayout was the end all do all layout manager for Java back in the day. Yes, I did some crazy layouts with it that worked and even allowed you to resize the panel and flow properly. The code was ugly and not maintainable. You could not look at it and tell what the hell was going to display on screen and you could not add a new control between other controls without totally screwing everything up. I worked with developers that used GridBagLayout for everything even though a simpler BorderLayout would have worked. Use the right tool for the job people.
Look Apple there were a ton of other good examples of how to do things. MigLayout for example if you only want one layout manager. The Android XML way of doing things if you don't might multiple layout managers that deal with each other. At least with Android you can layout portrait and landscape and just put them in different directories. There is a WYSIWYG viewer too. I use it to preview the code changes I make in XML and so far have been able to build every layout I have wanted. The Android side is not perfect but is better than what I have seen from Apple.
Nope, Apple just puts all of that on you. Now I get to manually code all this crap and other devs will be able to see what it looks like when they run the code.
I just wanted to convert a current screen from a table view to a normal view. The original developer misused a table view for the screen and I need to clean it up and give a better look. IB does not like it when you try to change view types. Time to punt. Yes, I am using Xcode 5.x and I know it is supposed to have better auto layout support but it is still a mess.
Having spoken to my other iOS developer friends they have all stated it is time to move as far away from IB as possible. It has done nothing but screw them over. They think I am a fool for attempting to stick with IB as long as I have. I really just wanted to get the current project off the books but that is not going to happen. I can try and blow away the current table with a normal view then reattach the segues to the new view and leave it at that but that seems a new waste of effort.
I am going to have to learn auto layout. It is the new Apple way of doing things. It is the only hope if Apple decides to ever come out with a new resolution, which I really think they should. People are expecting HDTV on their devices. 1024x768 on the iPad mini is not cutting it anymore.
Maybe someone will come out with an excellent layout manager for iOS that will solve a number of these issues. At this time I don't care about WYSIWYG at the start. Something that is easy to code and maintain is what I want. I enjoyed working with MigLayout. I converted over 300 Java desktop screens from old NetBeans format to MigLayout at a previous company. I find the Android layout managers more difficult that MigLayout but still serviceable. The new Android Studio does a really nice job showing me a preview of my screens as I edit the XML. The layouts work and scale on various device sizes.
Done with my rant. Off to code NSLayoutConstraints.
This meant if you wanted to support landscape you added code to move things around and resize them during orientation changes. You could still use IB to see that pristine portrait view. Then came the iPad which was used in landscape a lot. Just do IB in that mode.
Well IB sucks. Adding storyboards just allowed it to suck in some new ways. Sure you can tie you portrait screens together and you can do separate iPad and iPhone screens but you have to manually tie all the controls back to your source code with crazy Ctrl + Click drag and drop if you can get the right source file to appear in a squished down window below the stupid layout that is way too damn big for iPad screens that wants to constantly scroll and resize every freaking time you click on it!
You are an idiot - use auto layout. If you don't then you are hosed. But Apple did not backport that, you had to wait until most users were on iOS 6. Google backports, Apple does not. Apple is a jerk in this area. iOS 6 seems like a safe enough target at this point.
Auto layout has a new set of issues. IB really blows here. It has to have everything in perfect order even though when you are creating the layout you can't get it in perfect order until the layout is fully loaded with all the controls. They IB rewrites the damn file over and over. You lose the battle every single time wasting a huge amount of effort.
So screw IB, it has been screwing you. Besides if you want a team working on things they can't all have the storyboard open because version controls DIFF is nearly impossible. It is a SNAFU. Time to write it all in code and skip everything related to IB.
You have a couple of choices. Use the auto layout weird ASCII stuff, which is just ugly to read, or use NSLayoutConstraints manually. I think I am going NSLayoutConstraints. If I am getting no WYSIWYG support I might as well take full controls. That ASCII stuff is too bizarre. Honestly this all feels like I am moving back into the land of GridBagLayout in Java.
GridBagLayout was the end all do all layout manager for Java back in the day. Yes, I did some crazy layouts with it that worked and even allowed you to resize the panel and flow properly. The code was ugly and not maintainable. You could not look at it and tell what the hell was going to display on screen and you could not add a new control between other controls without totally screwing everything up. I worked with developers that used GridBagLayout for everything even though a simpler BorderLayout would have worked. Use the right tool for the job people.
Look Apple there were a ton of other good examples of how to do things. MigLayout for example if you only want one layout manager. The Android XML way of doing things if you don't might multiple layout managers that deal with each other. At least with Android you can layout portrait and landscape and just put them in different directories. There is a WYSIWYG viewer too. I use it to preview the code changes I make in XML and so far have been able to build every layout I have wanted. The Android side is not perfect but is better than what I have seen from Apple.
Nope, Apple just puts all of that on you. Now I get to manually code all this crap and other devs will be able to see what it looks like when they run the code.
I just wanted to convert a current screen from a table view to a normal view. The original developer misused a table view for the screen and I need to clean it up and give a better look. IB does not like it when you try to change view types. Time to punt. Yes, I am using Xcode 5.x and I know it is supposed to have better auto layout support but it is still a mess.
Having spoken to my other iOS developer friends they have all stated it is time to move as far away from IB as possible. It has done nothing but screw them over. They think I am a fool for attempting to stick with IB as long as I have. I really just wanted to get the current project off the books but that is not going to happen. I can try and blow away the current table with a normal view then reattach the segues to the new view and leave it at that but that seems a new waste of effort.
I am going to have to learn auto layout. It is the new Apple way of doing things. It is the only hope if Apple decides to ever come out with a new resolution, which I really think they should. People are expecting HDTV on their devices. 1024x768 on the iPad mini is not cutting it anymore.
Maybe someone will come out with an excellent layout manager for iOS that will solve a number of these issues. At this time I don't care about WYSIWYG at the start. Something that is easy to code and maintain is what I want. I enjoyed working with MigLayout. I converted over 300 Java desktop screens from old NetBeans format to MigLayout at a previous company. I find the Android layout managers more difficult that MigLayout but still serviceable. The new Android Studio does a really nice job showing me a preview of my screens as I edit the XML. The layouts work and scale on various device sizes.
Done with my rant. Off to code NSLayoutConstraints.
Labels:
auto layout,
interface builder,
ios,
layout,
stink
Wednesday, May 22, 2013
Core Data stinks for bulk inserts - direct SQLLite is much faster
I was handed an iOS app that was using the basic JSON handlers and keeping everything in memory. This was slow and running out of memory for large requests.
I converted the project to use stream based JSON parsing stored to a Core Data database backed by SQLLite. This solved the memory issues allowing all requests to work. There are 5 tables involved with a total of 239,000 records if you requested all the data from the server.
The problem - that request took 5 minutes and 43 seconds to process on an iPad 2. It took 33 seconds on the simulator. Let's state this again - Always test on a device. That kind of time is totally unacceptable.
After sniffing around the net and attempting to speed up Core Data I determined that Core Data sucks at doing bulk inserts. Core Data is really nice at hiding the gut level fun of SQLLite but for large inserts it is not the way to go.
I converted everything to use SQLLite directly and saw a massive speed increase. I can now process the same record set in 1 minute and 23 seconds. That cuts a whopping 4 minutes and 20 seconds off the time. The simulator went form 33 seconds to 12 seconds.
A typical user would rarely if ever request all the records but testing worst case scenario is really the best way to go. The speed improvement is seen across the board in the app with similar percentages of improvement. I am very happy with the results even though it took a couple of days to get it all sorted out.
As for the code there are areas that are more involved than the Core Data version and there are areas that are actually a lot cleaner. Everything is a trade off and there is no clear winner.
I had never used Core Data before. It was a really good learning experience to set it all up using the GUI editor in Xcode and finding out what it took to add the Core Data library and support code to an iOS project that was created without it originally. I found a lot of Core Data really straight forward and easy to use. I will not shy away from it on other projects unless they involve bulk inserts.
Having used SQLLite in the past I had a basic object set to start with and I knew my way around FMDatabase. My previous experience did bulk insert processing and I wrote both iOS and Android versions so I stuck with SQLLite to make it easier to convert code back and forth. I wanted to learn something new this time around so I went with Core Data. Good thing I could quickly fall back on my direct SQLLite experience to solve the speed issues that arose.
I converted the project to use stream based JSON parsing stored to a Core Data database backed by SQLLite. This solved the memory issues allowing all requests to work. There are 5 tables involved with a total of 239,000 records if you requested all the data from the server.
The problem - that request took 5 minutes and 43 seconds to process on an iPad 2. It took 33 seconds on the simulator. Let's state this again - Always test on a device. That kind of time is totally unacceptable.
After sniffing around the net and attempting to speed up Core Data I determined that Core Data sucks at doing bulk inserts. Core Data is really nice at hiding the gut level fun of SQLLite but for large inserts it is not the way to go.
I converted everything to use SQLLite directly and saw a massive speed increase. I can now process the same record set in 1 minute and 23 seconds. That cuts a whopping 4 minutes and 20 seconds off the time. The simulator went form 33 seconds to 12 seconds.
A typical user would rarely if ever request all the records but testing worst case scenario is really the best way to go. The speed improvement is seen across the board in the app with similar percentages of improvement. I am very happy with the results even though it took a couple of days to get it all sorted out.
As for the code there are areas that are more involved than the Core Data version and there are areas that are actually a lot cleaner. Everything is a trade off and there is no clear winner.
I had never used Core Data before. It was a really good learning experience to set it all up using the GUI editor in Xcode and finding out what it took to add the Core Data library and support code to an iOS project that was created without it originally. I found a lot of Core Data really straight forward and easy to use. I will not shy away from it on other projects unless they involve bulk inserts.
Having used SQLLite in the past I had a basic object set to start with and I knew my way around FMDatabase. My previous experience did bulk insert processing and I wrote both iOS and Android versions so I stuck with SQLLite to make it easier to convert code back and forth. I wanted to learn something new this time around so I went with Core Data. Good thing I could quickly fall back on my direct SQLLite experience to solve the speed issues that arose.
Tuesday, May 21, 2013
Mobile app usage and development - do you just have to magically know what to do?
The more mobile development I do the more I am finding you are just expected to know things magically. There are very few help screens, tips of the day or on screen tutorials. There are so many potential gestures in any app that you need to magically discover. What can we do to make this situation better?
A lot of apps allow swipes to perform an action. Swipe left to call, swipe right to text. Long presses may do something or bring up a menu. Some actions are instant and others prompt you but you are never really sure what will happen. Delete should prompt. Add a new item most likely does not need to unless it will cost money i.e. send a message or use your data plan or will take a long time to perform.
Some will answer the mobile device is so small and we all want to save on code size and people never use help or only use it once so skip it. The original apps were very small and had few features so that worked. News apps have a ton of features. We basically have computers in our pockets and we do a lot of work on them.
Do we need a standard "Cool Features" button showing quick help? Maybe it should show a standardized overlay on the screen to explain the swipes and long presses so people can get more out of our apps.
The other side of this is developer tools. They have a boat load of features too and a lot of their power is there but hidden from the coder. I know Xcode drives me crazy with its lack of right mouse button menus. I expect to be able to perform most actions a context sensitive menu. In general the menus are very terse. Want to add a view controller to a story board? Right click on the story board and you get zooming only options. You have to know to drag a view controller for the Utilities panel. But first the Utilities panel has to be visible. That is the only way to perform this operation. That is not friendly.
Speaking of the Utilities panel it has 6 tabs on it and I seem never to go to the correct one to do what I need. Do do nearly anything you shift between 2 or 3 of the tabs. Somehow I would like the most common settings on a single tab that I could define.
Right click on a segue control and you get zoom options but nothing associated to the segue. Click on the Scene Name in the left hand panel and nothing at all happens. I excepted the editor to scroll to that Scene. You have to click on a view of the scene for that to happen. Oh and it changes your zoom factor when you do that. Just scroll there! If I was zoomed out I want to stay zoomed out!
Is the layout of your windows wrong? Can you right click on something and fix it? No, you have to go to View -> Assistant Editor and pick the layout you want. I did not even know the window I was looking at was called Assistant Editor as nothing on screen indicates that. You can mouse hover over the toolbar button to find that out. Those same buttons are inconsistent. The first three toggle between modes of a view and only one can be pressed at any time. The next three toggle the visibility of views and any or none of them can be pressed but the two sets visually they look identical.
Highlight a word in the editor and hit Cmd+F most editors will automatically put the highlighted word in the search box but not Xcode. I get to copy / paste it up there. Heck I can highlight a word in Eclipse and just hit Ctrl+K to find the next occurrence skipping the Find prompt altogether.
Add files to a project and guess what? They are not flagged as needed to be added to version control. Why? Right click on them to add them and that menu is not there. I have to fire up SourceTree to add them to GIT for this to work. Xcode version control integration is crappy at best.
A lot of apps allow swipes to perform an action. Swipe left to call, swipe right to text. Long presses may do something or bring up a menu. Some actions are instant and others prompt you but you are never really sure what will happen. Delete should prompt. Add a new item most likely does not need to unless it will cost money i.e. send a message or use your data plan or will take a long time to perform.
Some will answer the mobile device is so small and we all want to save on code size and people never use help or only use it once so skip it. The original apps were very small and had few features so that worked. News apps have a ton of features. We basically have computers in our pockets and we do a lot of work on them.
Do we need a standard "Cool Features" button showing quick help? Maybe it should show a standardized overlay on the screen to explain the swipes and long presses so people can get more out of our apps.
The other side of this is developer tools. They have a boat load of features too and a lot of their power is there but hidden from the coder. I know Xcode drives me crazy with its lack of right mouse button menus. I expect to be able to perform most actions a context sensitive menu. In general the menus are very terse. Want to add a view controller to a story board? Right click on the story board and you get zooming only options. You have to know to drag a view controller for the Utilities panel. But first the Utilities panel has to be visible. That is the only way to perform this operation. That is not friendly.
Speaking of the Utilities panel it has 6 tabs on it and I seem never to go to the correct one to do what I need. Do do nearly anything you shift between 2 or 3 of the tabs. Somehow I would like the most common settings on a single tab that I could define.
Right click on a segue control and you get zoom options but nothing associated to the segue. Click on the Scene Name in the left hand panel and nothing at all happens. I excepted the editor to scroll to that Scene. You have to click on a view of the scene for that to happen. Oh and it changes your zoom factor when you do that. Just scroll there! If I was zoomed out I want to stay zoomed out!
Is the layout of your windows wrong? Can you right click on something and fix it? No, you have to go to View -> Assistant Editor and pick the layout you want. I did not even know the window I was looking at was called Assistant Editor as nothing on screen indicates that. You can mouse hover over the toolbar button to find that out. Those same buttons are inconsistent. The first three toggle between modes of a view and only one can be pressed at any time. The next three toggle the visibility of views and any or none of them can be pressed but the two sets visually they look identical.
Highlight a word in the editor and hit Cmd+F most editors will automatically put the highlighted word in the search box but not Xcode. I get to copy / paste it up there. Heck I can highlight a word in Eclipse and just hit Ctrl+K to find the next occurrence skipping the Find prompt altogether.
Add files to a project and guess what? They are not flagged as needed to be added to version control. Why? Right click on them to add them and that menu is not there. I have to fire up SourceTree to add them to GIT for this to work. Xcode version control integration is crappy at best.
Wednesday, April 24, 2013
Using YAJL with Objective C
I have been tasked with getting an existing iOS code base ready to be released to the App Store. After loading the existing project into Xcode and resolving static library link issues I was able to run the program but not log in. I added some #ifdef DEBUG processing to allow me to log into a server without a valid certificate and got to play around in the app on the simulator.
I was quickly able to crash the app and after setting the debugger up to stop on all exceptions I found it was running out of memory. Boy, if you can run the simulator out of memory you know you can easily do that on a device.
Looking through the code I found it was using NSJSONSerialization for all JSON processing. That library is fine and it is provided by Apple so you know it is legal to use but when you have large amounts of data it is not super efficient. If you have used XML in the past and are just getting into JSON this is similar to using DOM vs SAX. DOM is great and easy and hands you a nice tree of data but if all you are doing is plucking things out of that tree to put in another format you are better off using SAX especially if there are memory concerns.
The code was parsing everything into a big NSDictionary based tree with 13,318 base records and tons more child records. This is just not going to work on a memory limited device.
I looked up information on stream based JSON parsers and landed on YAJL which you can find at https://github.com/gabriel/yajl-objc. I won't cover how to configure it for Xcode as all that information is on the base site. It was easy to set up for both Mac OSX (my test program) and iOS.
They show a streaming sample that was too basic to be very helpful. Hopefully I can fill in some of the gaps. The first issue with their sample is they read the WHOLE file into memory via NSData then run it through the parser. Not fully streaming at that point. Second they show no samples on what to do in the callbacks.
The code snippet below will help you parse your JSON by keeping track of where you are in the data. It will keep a stack of named dictionaries and arrays as you parse through the data. You can then create and act on the proper objects as you get map keys and values.
It also reads in the JSON file in chunks instead of tossing the whole things into NSData. In my final iOS code I am using a NSURLConnection and parsing the chunks in the didReceiveData call.
The original code ran out of memory when receiving 38.9 meg of data and took 5 seconds to run. I put in some cheater try / catch blocks to let it "finish" without crashing for timing results. The new code does not run out of memory and runs in 2 seconds. Of course this is all in the simulator on a fast MacBook Pro with a lot of RAM. I don't currently have a device to test on but will get one soon.
I looked around on the web for a long time before I was able to piece together enough knowledge to pull this off so hopefully it will help others get up to speed a lot faster.
Things that go in the header file
// Array used as a stack to keep track of where we are
NSMutableArray *stack; // create this in init method
NSString *mapKey;
// Actual class code
- (id) init
{
self = [super init];
if (self != nil) {
stack = [[NSMutableArray alloc] init];
}
return self;
}
// Code to parse the file in chunks
- (void) parseFile:(NSString *)jsonFileName
{
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsAllowComments];
parser.delegate = self;
uint64 offset = 0;
uint32 chunkSize = 10240; //Read 10KB chunks.
NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:jsonFileName];
NSData *data = [handle readDataOfLength:chunkSize];
NSLog(@"Starting parse of %@...", jsonFileName);
[stack removeAllObjects];
mapKey = nil;
while ([data length] > 0)
{
[parser parse:data];
if (parser.parserError)
{
NSLog(@"Error:\n%@", parser.parserError);
}
offset += [data length];
[handle seekToFileOffset:offset];
data = [handle readDataOfLength:chunkSize];
}
[handle closeFile];
parser.delegate = nil;
}
// Stack adds newly named object OR last object on stack
- (void)parserDidStartDictionary:(YAJLParser *)parser
{
NSString *dictName = mapKey;
if (mapKey == nil)
{
dictName = (stack.count == 0) ? @"" : [stack lastObject];
}
[stack addObject:(dictName)];
// Create new object here based on dictionary name
// ready to hold soon to come key + value pairs
}
// End of dictionary - pop off stack
- (void)parserDidEndDictionary:(YAJLParser *)parser
{
mapKey = nil;
[stack removeLastObject];
// Save object created in start Dictionary to
// array or core data here
}
// New array staring, push name onto stack (use previous if we don't have one)
- (void)parserDidStartArray:(YAJLParser *)parser
{
NSString *arrayName = mapKey;
if (mapKey == nil)
{
arrayName = stack.count == 0 ? @"" : [stack lastObject];
}
[stack addObject:(arrayName)];
}
// End of array, pop off stack
- (void)parserDidEndArray:(YAJLParser *)parser
{
mapKey = nil;
[stack removeLastObject];
}
- (void)parser:(YAJLParser *)parser didMapKey:(NSString *)key
{
mapKey = key;
// Do processing here for each map key
// Something like
// if (!inResults && [key isEqualToString:@"results"])
// {
// inResults = true;
// }
}
- (void)parser:(YAJLParser *)parser didAdd:(id)value
{
// Do processing here for each value (will have a mapKey)
// Something like
// if (inResults && [mapKey isEqualToString:@"query"])
// {
// query = ((NSString *)value);
// }
//
// value will be (NSString *), (NSNull *) or (NSNumber *)
// booleans come as (NSNumber *) 0 = false, 1 = true
}
I was quickly able to crash the app and after setting the debugger up to stop on all exceptions I found it was running out of memory. Boy, if you can run the simulator out of memory you know you can easily do that on a device.
Looking through the code I found it was using NSJSONSerialization for all JSON processing. That library is fine and it is provided by Apple so you know it is legal to use but when you have large amounts of data it is not super efficient. If you have used XML in the past and are just getting into JSON this is similar to using DOM vs SAX. DOM is great and easy and hands you a nice tree of data but if all you are doing is plucking things out of that tree to put in another format you are better off using SAX especially if there are memory concerns.
The code was parsing everything into a big NSDictionary based tree with 13,318 base records and tons more child records. This is just not going to work on a memory limited device.
I looked up information on stream based JSON parsers and landed on YAJL which you can find at https://github.com/gabriel/yajl-objc. I won't cover how to configure it for Xcode as all that information is on the base site. It was easy to set up for both Mac OSX (my test program) and iOS.
They show a streaming sample that was too basic to be very helpful. Hopefully I can fill in some of the gaps. The first issue with their sample is they read the WHOLE file into memory via NSData then run it through the parser. Not fully streaming at that point. Second they show no samples on what to do in the callbacks.
The code snippet below will help you parse your JSON by keeping track of where you are in the data. It will keep a stack of named dictionaries and arrays as you parse through the data. You can then create and act on the proper objects as you get map keys and values.
It also reads in the JSON file in chunks instead of tossing the whole things into NSData. In my final iOS code I am using a NSURLConnection and parsing the chunks in the didReceiveData call.
The original code ran out of memory when receiving 38.9 meg of data and took 5 seconds to run. I put in some cheater try / catch blocks to let it "finish" without crashing for timing results. The new code does not run out of memory and runs in 2 seconds. Of course this is all in the simulator on a fast MacBook Pro with a lot of RAM. I don't currently have a device to test on but will get one soon.
I looked around on the web for a long time before I was able to piece together enough knowledge to pull this off so hopefully it will help others get up to speed a lot faster.
Things that go in the header file
// Array used as a stack to keep track of where we are
NSMutableArray *stack; // create this in init method
NSString *mapKey;
// Actual class code
- (id) init
{
self = [super init];
if (self != nil) {
stack = [[NSMutableArray alloc] init];
}
return self;
}
// Code to parse the file in chunks
- (void) parseFile:(NSString *)jsonFileName
{
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsAllowComments];
parser.delegate = self;
uint64 offset = 0;
uint32 chunkSize = 10240; //Read 10KB chunks.
NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:jsonFileName];
NSData *data = [handle readDataOfLength:chunkSize];
NSLog(@"Starting parse of %@...", jsonFileName);
[stack removeAllObjects];
mapKey = nil;
while ([data length] > 0)
{
[parser parse:data];
if (parser.parserError)
{
NSLog(@"Error:\n%@", parser.parserError);
}
offset += [data length];
[handle seekToFileOffset:offset];
data = [handle readDataOfLength:chunkSize];
}
[handle closeFile];
parser.delegate = nil;
}
// Stack adds newly named object OR last object on stack
- (void)parserDidStartDictionary:(YAJLParser *)parser
{
NSString *dictName = mapKey;
if (mapKey == nil)
{
dictName = (stack.count == 0) ? @"" : [stack lastObject];
}
[stack addObject:(dictName)];
// Create new object here based on dictionary name
// ready to hold soon to come key + value pairs
}
// End of dictionary - pop off stack
- (void)parserDidEndDictionary:(YAJLParser *)parser
{
mapKey = nil;
[stack removeLastObject];
// Save object created in start Dictionary to
// array or core data here
}
// New array staring, push name onto stack (use previous if we don't have one)
- (void)parserDidStartArray:(YAJLParser *)parser
{
NSString *arrayName = mapKey;
if (mapKey == nil)
{
arrayName = stack.count == 0 ? @"" : [stack lastObject];
}
[stack addObject:(arrayName)];
}
// End of array, pop off stack
- (void)parserDidEndArray:(YAJLParser *)parser
{
mapKey = nil;
[stack removeLastObject];
}
- (void)parser:(YAJLParser *)parser didMapKey:(NSString *)key
{
mapKey = key;
// Do processing here for each map key
// Something like
// if (!inResults && [key isEqualToString:@"results"])
// {
// inResults = true;
// }
}
- (void)parser:(YAJLParser *)parser didAdd:(id)value
{
// Do processing here for each value (will have a mapKey)
// Something like
// if (inResults && [mapKey isEqualToString:@"query"])
// {
// query = ((NSString *)value);
// }
//
// value will be (NSString *), (NSNull *) or (NSNumber *)
// booleans come as (NSNumber *) 0 = false, 1 = true
}
Saturday, November 24, 2012
Only doing Android work - what a change of pace
At my new position I am only doing Android development where before I was doing Android / iPhone and desktop Java. First off it is a bit weird only having one computer, one IDE, one mouse and one keyboard to deal with. Everything is the same each day. You don't have to mentally switch gears multiple times a week.
What it does make you think about is pushing the one platform you are on even farther than before. I was always in a bit of a rush. I needed this working on both iOS and Android so I got it working on each but maybe not the best on each. Now I can say "I need this working on the Android and I need to to work and look the best possible." I don't care if what I am doing it pain in the behind on iOS, there is another team to worry about that. I don't have to think about desktop Java at all.
I am finding this new mentality is really helping me discover areas of the Android platform I had not had the time or energy to investigate in the past. I have been playing around with animations. We need to swap an image view between the front and back of a check. I started with a simple one, changed it to a fade in / fade out as suggested by another developer then I switched it again on Friday to a simple animation that makes it look the check is flipping. I am pretty happy with the current iteration.
The other bonus is I have the ear of a second Android developer. Being the solo mobile guy at the last place had a number of disadvantages. No one to bounce ideas off of, do code reviews, suggest a better way, a new animation, better color schemes, different layout ideas etc. The other guy has a lot of different Android experience than I do. He had worked with JSON before so got that part running quickly. I had done custom controls and a lot of layouts so I had that handled. We both know to use styles, the string table and other XML files to keep things clean.
The code we inherited looked like it was the first Android project written by this off shore team. We had a lot of general clean up to do before we even wanted to touch the guts as they did not follow any of the general Android guidelines.
We are finishing up the process of making this a real Android app. They locked all the screens into portrait. That may be acceptable for a game but not for a main text based application. The iPhone team locked it all into portrait too because doing both portrait and landscape under iOS can be a pain. Sure, there are some gotchas in Android but it is pretty darn flexible on the layout side of things and it is easy to create the directories you need. Plus we are working on having it look nice on phones and tablets. The iOS team is not doing a universal app so iPad owners will get the less the satisfactory 2x experience.
They are not too worried about Android tablets telling us there is little demand there. Not sure they are looking forward enough. There are going to be a lot of 7" tablets from Google and Amazon under the tree this year along with iPads and iPad minis. I know I use my tablet a lot around the house and I figure more and more people will be using them too. For this battle I am making sure it looks nice and is operational on a tablet. It is not tablet optimized but if you use a tablet I don't want you to scream and run away when you fire up this application.
I would suggest they do a universal app for iOS too but I think that will fall on deaf ears. The current team is very new to iOS, learning it on the fly in fact. Since I sit a converted break room with the other Android developer and two of the iOS team I get to hear their issues. Most of them I know about having done iOS development for a year. At least they are going after iOS 5.x and above and can use the new memory management aspect. The current code does not but all new code can. That will be a huge help. I was using that on the final iPad project I worked on at the old job and I know I could get used to doing it.
The one thing I really miss from the old job is dual 24" monitors. I have a dual screen set up now, the laptop screen and a 21" screen with a less than stellar resolution. The Android emulator barely fits on a screen height wise. Developing means you have a ton of windows open: Outlook, instant messenger, browser, text editor for notes, Eclipse, emulator, music player, command prompt, paint program, etc. These little 1400x900 screens just don't cut it. A a contractor I am considering picking up a bigger screen and hauling it in just to keep my self slightly sane. Companies need to realize how important screen space is to a developer. My dual screen set up at home is a better configuration than I have at work and that is kind of sad.
All in all it has been a good experience so far. They have work lined up so I know there is plenty to do. I am becoming a better Android programmer every day and using more of what the SDK has to offer. As long as I am growing at a job I am happy. The people are friendly and having another Android coder next to me has be a huge help.
What it does make you think about is pushing the one platform you are on even farther than before. I was always in a bit of a rush. I needed this working on both iOS and Android so I got it working on each but maybe not the best on each. Now I can say "I need this working on the Android and I need to to work and look the best possible." I don't care if what I am doing it pain in the behind on iOS, there is another team to worry about that. I don't have to think about desktop Java at all.
I am finding this new mentality is really helping me discover areas of the Android platform I had not had the time or energy to investigate in the past. I have been playing around with animations. We need to swap an image view between the front and back of a check. I started with a simple one, changed it to a fade in / fade out as suggested by another developer then I switched it again on Friday to a simple animation that makes it look the check is flipping. I am pretty happy with the current iteration.
The other bonus is I have the ear of a second Android developer. Being the solo mobile guy at the last place had a number of disadvantages. No one to bounce ideas off of, do code reviews, suggest a better way, a new animation, better color schemes, different layout ideas etc. The other guy has a lot of different Android experience than I do. He had worked with JSON before so got that part running quickly. I had done custom controls and a lot of layouts so I had that handled. We both know to use styles, the string table and other XML files to keep things clean.
The code we inherited looked like it was the first Android project written by this off shore team. We had a lot of general clean up to do before we even wanted to touch the guts as they did not follow any of the general Android guidelines.
We are finishing up the process of making this a real Android app. They locked all the screens into portrait. That may be acceptable for a game but not for a main text based application. The iPhone team locked it all into portrait too because doing both portrait and landscape under iOS can be a pain. Sure, there are some gotchas in Android but it is pretty darn flexible on the layout side of things and it is easy to create the directories you need. Plus we are working on having it look nice on phones and tablets. The iOS team is not doing a universal app so iPad owners will get the less the satisfactory 2x experience.
They are not too worried about Android tablets telling us there is little demand there. Not sure they are looking forward enough. There are going to be a lot of 7" tablets from Google and Amazon under the tree this year along with iPads and iPad minis. I know I use my tablet a lot around the house and I figure more and more people will be using them too. For this battle I am making sure it looks nice and is operational on a tablet. It is not tablet optimized but if you use a tablet I don't want you to scream and run away when you fire up this application.
I would suggest they do a universal app for iOS too but I think that will fall on deaf ears. The current team is very new to iOS, learning it on the fly in fact. Since I sit a converted break room with the other Android developer and two of the iOS team I get to hear their issues. Most of them I know about having done iOS development for a year. At least they are going after iOS 5.x and above and can use the new memory management aspect. The current code does not but all new code can. That will be a huge help. I was using that on the final iPad project I worked on at the old job and I know I could get used to doing it.
The one thing I really miss from the old job is dual 24" monitors. I have a dual screen set up now, the laptop screen and a 21" screen with a less than stellar resolution. The Android emulator barely fits on a screen height wise. Developing means you have a ton of windows open: Outlook, instant messenger, browser, text editor for notes, Eclipse, emulator, music player, command prompt, paint program, etc. These little 1400x900 screens just don't cut it. A a contractor I am considering picking up a bigger screen and hauling it in just to keep my self slightly sane. Companies need to realize how important screen space is to a developer. My dual screen set up at home is a better configuration than I have at work and that is kind of sad.
All in all it has been a good experience so far. They have work lined up so I know there is plenty to do. I am becoming a better Android programmer every day and using more of what the SDK has to offer. As long as I am growing at a job I am happy. The people are friendly and having another Android coder next to me has be a huge help.
Saturday, November 10, 2012
Life at the new job and a Galaxy Note as my testing device
Life at the new job has been interesting. They did not have an official place for me to sit on the first day so I took over the office of a guy who is on vacation. They found a place over in customer support so I moved there for a bit and now will move to a more permanent home in what use to be a small conference room that is being divided into 4 cubes. I will be in there with another Android developer and two iPhone developers. Will help us share a lot of ideas.
For my main testing device they gave me a Galaxy Note - original version not the new II. For some reason I thought it was going to be much larger as all the reviews jump all over that. It is larger than my main phone, a Galaxy S Vibrant. I actually like the size. Larger than my phone but not a tablet. I have been using it a lot a night to see what I think of it as I have considered getting a Note II when it goes on Black Friday sale, or at least I hope it goes on sale.
I wish the S-Pen worked a bit faster. I am hoping it does a better job keeping up on the Note II. On the model I have I must slow down my standard writing speed to have it draw what I think it is going to draw. I should not have to adjust to what the device can do, it should keep up with me. I have used the phone as a mini whiteboard. Again, drawing speed is a little slow but if I match the pace it works well. Using it to jot down notes at home is also handy, it sits right next to me and saves me from hunting down paper to remember something like "out of cat food". You can easily erase mistakes in your drawings too. I think this could be a great feature.
As far as a testing device it is really nice. Samsung seems to be very quick to grab back memory you once used and to kill activities as you move between them. It allows me to simulate low memory usage that would occur on a phone. This really comes into play as I am doing a lot of importing of images from the camera activity which is one area you can quickly run into memory limitations. I have been able to fix all the issues I have run into and make my code much more low memory proof than previous code I have written. Allowed me to learn all sorts of interesting things about Android programming.
After using the phone for about a week I would say it is a winner. I have been using it at night instead of my Xoom when I put my son to bed. At that time I am generally reading web pages, using Pulse or maybe playing a game. Being able to do that with one hand is really nice. I don't know if a 7" tablet would allow me to do the same thing or not as I don't have access to one. The Note fits in the hand without cramping. The screen is very bright and readable. I only charge is once a day. Web pages tend to be read in landscape mode but that works just fine. You get the side to side space you need for most websites but you do have to to a bit more scrolling vertically as you read pages. Nothing that is annoying, just something to keep in mind.
After I have time to test the S-Pen drawing speed on a Note II and it goes on sale I will probably buy one as my next personal device. I love the Xoom tablet and use it a lot. My phone is getting older and it only runs 2.2 which is pretty crappy. I need to use some of the new Android OS features to keep up with the programming world.
Working strictly on mobile development at my job has been nice. No shifting gears between iOS, Android and desktop Java during the day. One keyboard, mouse, language and IDE to keep straight. I am happy I know Objective C so I can look at the code and see what they did as my first project is a conversion of the automatic check deposit functionality, thus me taking a lot of pictures. I am sure my cube mates are sick of hearing the sound of a camera shutter as am I. Friday morning I fixed my threading issue so I stopped taking pictures and started looking into the server API for send the deposits.
Being as I am a contractor I get to work Monday which the perms have the day off for Veteran's Day. I will be happy when I convert to a full time person allowing me to have all the bank holidays off like I did when I worked in the stock market industry.
For my main testing device they gave me a Galaxy Note - original version not the new II. For some reason I thought it was going to be much larger as all the reviews jump all over that. It is larger than my main phone, a Galaxy S Vibrant. I actually like the size. Larger than my phone but not a tablet. I have been using it a lot a night to see what I think of it as I have considered getting a Note II when it goes on Black Friday sale, or at least I hope it goes on sale.
I wish the S-Pen worked a bit faster. I am hoping it does a better job keeping up on the Note II. On the model I have I must slow down my standard writing speed to have it draw what I think it is going to draw. I should not have to adjust to what the device can do, it should keep up with me. I have used the phone as a mini whiteboard. Again, drawing speed is a little slow but if I match the pace it works well. Using it to jot down notes at home is also handy, it sits right next to me and saves me from hunting down paper to remember something like "out of cat food". You can easily erase mistakes in your drawings too. I think this could be a great feature.
As far as a testing device it is really nice. Samsung seems to be very quick to grab back memory you once used and to kill activities as you move between them. It allows me to simulate low memory usage that would occur on a phone. This really comes into play as I am doing a lot of importing of images from the camera activity which is one area you can quickly run into memory limitations. I have been able to fix all the issues I have run into and make my code much more low memory proof than previous code I have written. Allowed me to learn all sorts of interesting things about Android programming.
After using the phone for about a week I would say it is a winner. I have been using it at night instead of my Xoom when I put my son to bed. At that time I am generally reading web pages, using Pulse or maybe playing a game. Being able to do that with one hand is really nice. I don't know if a 7" tablet would allow me to do the same thing or not as I don't have access to one. The Note fits in the hand without cramping. The screen is very bright and readable. I only charge is once a day. Web pages tend to be read in landscape mode but that works just fine. You get the side to side space you need for most websites but you do have to to a bit more scrolling vertically as you read pages. Nothing that is annoying, just something to keep in mind.
After I have time to test the S-Pen drawing speed on a Note II and it goes on sale I will probably buy one as my next personal device. I love the Xoom tablet and use it a lot. My phone is getting older and it only runs 2.2 which is pretty crappy. I need to use some of the new Android OS features to keep up with the programming world.
Working strictly on mobile development at my job has been nice. No shifting gears between iOS, Android and desktop Java during the day. One keyboard, mouse, language and IDE to keep straight. I am happy I know Objective C so I can look at the code and see what they did as my first project is a conversion of the automatic check deposit functionality, thus me taking a lot of pictures. I am sure my cube mates are sick of hearing the sound of a camera shutter as am I. Friday morning I fixed my threading issue so I stopped taking pictures and started looking into the server API for send the deposits.
Being as I am a contractor I get to work Monday which the perms have the day off for Veteran's Day. I will be happy when I convert to a full time person allowing me to have all the bank holidays off like I did when I worked in the stock market industry.
Thursday, October 4, 2012
Which way to go for mobile permissions?
Which way do you like better for mobile permissions - Android or iOS? Android has you build the permissions into the program via the manifest file. iOS asks for permissions as the program runs. Both have pros and cons.
Android
Pros:
Developer decides on a list of required permissions, must adhere to them
Compiler enforces permissions
User gets to see all permissions at time of program install / upgrade
Permissions as static and included in app binary, don't have to be stored in associated data area of device
Cons:
Permission list may change during OS updates
User forced to read list during install, most ignore and just install, later complain you did something crazy
Some permissions are not granular enough
Some permission you would like to have but are not required to run - how to handle that?
iOS
Pros:
Developer codes away, does not really have to think about it
Old cheating programs are now caught when action is requested
New permissions can be prompted with OS upgrade
Cons:
User is bothered during program run, might scare them
Developers were able to cheat before, can still cheat until OS upgrade catches them
OS trust instead of IDE support, your app could fail due to user saying NO, defensive programmer for run time issues
Need special storage to keep track of each permission granted per application
User has to go under settings, privacy to find what they have granted if they want to make changes
I am undecided on which way I like better. I am happy to see iOS is now addressing this issue. Previously it was the wild west in iOS land. I just saw a prompt while running my code as I allow you to choose images from the gallery to attach to medical cases. What I am doing is innocent but I can see where programs could easily abuse this privilege. I was pleased to see the prompt appear and to have it only prompt once.
Android
Pros:
Developer decides on a list of required permissions, must adhere to them
Compiler enforces permissions
User gets to see all permissions at time of program install / upgrade
Permissions as static and included in app binary, don't have to be stored in associated data area of device
Cons:
Permission list may change during OS updates
User forced to read list during install, most ignore and just install, later complain you did something crazy
Some permissions are not granular enough
Some permission you would like to have but are not required to run - how to handle that?
iOS
Pros:
Developer codes away, does not really have to think about it
Old cheating programs are now caught when action is requested
New permissions can be prompted with OS upgrade
Cons:
User is bothered during program run, might scare them
Developers were able to cheat before, can still cheat until OS upgrade catches them
OS trust instead of IDE support, your app could fail due to user saying NO, defensive programmer for run time issues
Need special storage to keep track of each permission granted per application
User has to go under settings, privacy to find what they have granted if they want to make changes
I am undecided on which way I like better. I am happy to see iOS is now addressing this issue. Previously it was the wild west in iOS land. I just saw a prompt while running my code as I allow you to choose images from the gallery to attach to medical cases. What I am doing is innocent but I can see where programs could easily abuse this privilege. I was pleased to see the prompt appear and to have it only prompt once.
Thursday, September 20, 2012
Xcode 4.5 iOS 6 iPhone 5 simulator issues
Last night before I left I begin the Xcode 4.5 official release download. This morning it was ready to roll and then it needed to update a few other areas of Xcode but it was up and running pretty quickly. I then went about the work of having my app make use of the full height of the iPhone 5 screen.
Xcode asked if I wanted to add the Default-568h@2x.png which I allowed it to do. I knew that was one of the requirements so I was very happy it created the all black image for me. Our launch time is super fast so I don't need a real launch image.
Next I knew the rotation messages needed a massage. I add the following lines to all the ViewControllers allowing all orientations to work.
// OS 6 rotate message
- (BOOL)shouldAutorotate {
return YES;
}
// OS 6 rotate message response
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
I left the original orientation code in place for non-iOS 6 devices.
Time to tweak the rootViewController
// Changed for iOS 6
self.window.rootViewController = self.navigationController;
// [window addSubview:navigationController.view];
I had to switch to libxml2.2.dylib for libxlm.2.2.7.3.dylib for my frameworks. Not sure why the newer Xcode has what appears to be an older version of this lib but everything appears to work using it.
I download older simulators (4.3 and 5.1) so I can test as many as possible without swapping devices.
Adjusting the home screen paint for extra size by checking for iPhone 5 resolution and putting our logo below the grid of buttons on the portrait version makes that look nice. Putting extra space between each icon on landscape mode to space them evenly across the screen gives that area the proper look.
All the other screens filled the new height and went smoothly and things look great except for one big issue I have not yet been able to resolve. The back button in the navigation bar does not work in the simulator. Well it does work for everything but an iPhone (Retina 4-inch). I can choose iOS 4.3, 5.1 or 6.0 and any device - iPhone, iPhone (Retina 3.5-inch), iPad, iPad (Retina) - and everything about my program works just fine. Once I set the hardware to be iPhone (Retina 4-inch) then the buttons will not work. Nothing happens when I click on them, no errors, no highlighting, no action at all.
Seems to me I am not having an iOS 6.0 issue but a simulator issue. Until I get my hands on some real hardware I am not sure what to do. I can install iOS 6.0 on my iPad 2 or my third gen iTouch but that does not tell me if things have gone haywire on a real iPhone 5.
The other area of fun is two of my hardware testing devices are no longer supported by Xcode 4.5. I can't use the second generation iTouch or the iPhone 3G. They are both stuck at iOS 4.2.1. We checked our logs and it appears we still have a user with that flavor of iOS. If I update the software I would set 4.3 as the minimum. Users would either stick with the version they have, upgrade their iOS if possible or buy new hardware. Apple is sort of forcing things along in this area. Even the original iPad has hit the end of its upgrade cycle.
At this point I get to keep digging to find out why the simulator is not letting me press the back button or the menu button I have at the other end of the navigation area on the 4" iPhone. Pretty obvious that I will not even think of releasing a new cut of the program until this is resolved. Sure, the simulator can be hosed as long as the code runs on a real device I will be fine. I really am hoping it is a code tweak to make it work across the board. Right now 4" iPhone information is pretty sparse.
** UPDATE ** Not fixed but I did try rotating the screen in the simulator. The buttons started to work. Then I rotated again and they stopped, then again and the back button would work but not the menu button. At times all buttons will work then will stop working. Rotation may or may not allow them to work again. I really does appear the simulator has an issue in this area.
** FIXED ** I had to open my MainWindow.XIB file, select the Window object and ticked "Full Screen at Launch". Now everything appears to be working on all simulator devices. I need to beat on the application for a bit more but now I at least feel safe checking in the code changes I have made. Hope this knowledge can help out someone else.
Wednesday, July 18, 2012
iOS developer woes
I am working on a new iPad program. It will allow an anesthesiologist at a facility to shift around the appointments of the providers in his group. Scheduled surgeries run late and there are a variety of other reasons to shift things about.
I got back into the CGContext side of programming under iOS and have the time margin, row headers and basic grid painting up and running. I wanted to see how this looked on the physical device before I got much farther along. Not allowed.
My iPad has been updated to iOS 5.1x. I am targeting iOS 5.0x but since the iPad has received the OTA updates it is past that. You are not allowed to get the iOS 5.1x SDK without Xcode 4.3.x and you are not allowed to get Xcode 4.3.x without Lion.
A couple of things stink here. Before Apple moved Xcode to the App Store you could download the DMG file and extract the iOS 5.1.x SDK files and use them with Xcode 4.2.x. That is no longer the case. In fact it appears you need to uninstall Xcode 4.2 before you install 4.3 as the new install directory is App Store based and not developer based like it was before.
Reviews of Xcode 4.3 are not glowing. Appears to be more crash happy than 4.2. Xcode has always been a flaky IDE but it is the only one in town. Yes you can use AppCode from IntelliJ but you still need Xcode installed for debugging and Interface Builder.
We need to upgrade to Lion but that is silly to do when Mountain Lion is due out in a week for $20. That means I need to wait but there will probably be an onslaught of others upgrading at the same time and it will not be a small download. Servers will be hit hard and heavy.
Xcode is a massive download at 1.43g but am I allowed to get that now? No, the App Store will not allow me to download that since I don't have Lion. I will have to fully upgrade before I can start the next monster download. This is going to take multiple days with me leaving the laptop on overnight for downloads. I can't queue things up either.
I think this will be my order of execution:
Uninstall Xcode 4.2
Upgrade to Mountain Lion
Install Xcode 4.3 from App Store
Hope all my projects still work, Mountain Lion is stable and Xcode is not super crash happy.
I could downgrade my iPad to iOS 5.0 to do my testing. That would work as a temp solution but it is not my iPad, it is used by QA and Technical Writing. Since the update is OTA and it will ask about it there is a very strong chance it will be updated again once it is off my desk for a few minutes.
I just hope nothing goes wrong during all these changes. I was using VNC on my PC to do Mac programming. It is my understanding that VNC is rather broken under Lion and I have not heard that they addressed that under Mountain Lion. My whole development environment is being turned upside down.
I got back into the CGContext side of programming under iOS and have the time margin, row headers and basic grid painting up and running. I wanted to see how this looked on the physical device before I got much farther along. Not allowed.
My iPad has been updated to iOS 5.1x. I am targeting iOS 5.0x but since the iPad has received the OTA updates it is past that. You are not allowed to get the iOS 5.1x SDK without Xcode 4.3.x and you are not allowed to get Xcode 4.3.x without Lion.
A couple of things stink here. Before Apple moved Xcode to the App Store you could download the DMG file and extract the iOS 5.1.x SDK files and use them with Xcode 4.2.x. That is no longer the case. In fact it appears you need to uninstall Xcode 4.2 before you install 4.3 as the new install directory is App Store based and not developer based like it was before.
Reviews of Xcode 4.3 are not glowing. Appears to be more crash happy than 4.2. Xcode has always been a flaky IDE but it is the only one in town. Yes you can use AppCode from IntelliJ but you still need Xcode installed for debugging and Interface Builder.
We need to upgrade to Lion but that is silly to do when Mountain Lion is due out in a week for $20. That means I need to wait but there will probably be an onslaught of others upgrading at the same time and it will not be a small download. Servers will be hit hard and heavy.
Xcode is a massive download at 1.43g but am I allowed to get that now? No, the App Store will not allow me to download that since I don't have Lion. I will have to fully upgrade before I can start the next monster download. This is going to take multiple days with me leaving the laptop on overnight for downloads. I can't queue things up either.
I think this will be my order of execution:
Uninstall Xcode 4.2
Upgrade to Mountain Lion
Install Xcode 4.3 from App Store
Hope all my projects still work, Mountain Lion is stable and Xcode is not super crash happy.
I could downgrade my iPad to iOS 5.0 to do my testing. That would work as a temp solution but it is not my iPad, it is used by QA and Technical Writing. Since the update is OTA and it will ask about it there is a very strong chance it will be updated again once it is off my desk for a few minutes.
I just hope nothing goes wrong during all these changes. I was using VNC on my PC to do Mac programming. It is my understanding that VNC is rather broken under Lion and I have not heard that they addressed that under Mountain Lion. My whole development environment is being turned upside down.
Friday, January 20, 2012
Ouch - App Store rejection!
After a full week of waiting to review our app got rejected by the Apple app store. They found a crash, a legitimate and easy to reproduce crash that should have never made it past me or QA. A crash that occurred in all previous versions of the software. A crash that made it through to the store multiple times.
It involved turning off some of the editable sections via the admin tool. I was using a tag as an array offset, if all sections are enabled the tag would equal the offset, but in the one test case this was going to cause an index out of bounds. I screwed up and should have labeled the variable as tag instead of as section. I probably was going to do that at one point but the crappy refactoring support in Xcode means I skip doing work like that from time to time.
It is my fault for not catching this earlier. For the test log in we sent to Apple you had three practices to choose from. The bug only occurred on the third practice in the list and only when you pressed the (+) to add a new image to list. Very glad Apple found this issue. I did not want a crash out in the hands of our users and I am sure many would have run into this issue as the layout of the editable items is totally configuration via our administration tool. That tool is not a mobile app but how each client configures what they want the doctor to enter is totally up to them. Annoying this was not caught by QA. As a developer you don't have time to configure piles of test cases in the admin tool then test things out on the mobile side of things. Something like this I should have tested though as it is pretty easy to configure and verify.
It works just fine on the Android. Due to language and GUI component differences the code is not a direct port between the platforms. Could be I was doing a quick conversion to the iPhone or I did the iPhone side first and caught the issue during the Android conversion or the Android code is so different that bug would not occur or I forget to go fix it under iOS post Android conversion. I was back and forth between the two on a daily basis.
Being the sole developer for two platforms is just not easy. I have no one here that can do Objective C code reviews. Someone could look over the Android Java code but I am the only Android developer so some parts of the API would not be familiar too them. Java tends to be Java so I am sure they could find issues if they looked hard enough. Heck, I could find issues if I gave it all a once over. I fixed the issue, ran some tests and we submitted it again.
Within an hour it was back in "In Review" status so Apple obviously saw we got right on the fix and did not move us back to the end of the line. I really did not want our clients to wait another full week for Apple to just start looking at the app again. I am hopeful it gets through the review process in a few hours and we can contact clients starting Monday to let them know a new version is ready that fixes the camera issues and this new issue.
I just got another note from Apple that they need additional review time but they will keep me posted. Must be time for a real test instead of the past two times where it was just shuffled right out into production.
We don't appear to be getting crash reports from Apple. When we look in the crash report section nothing is listed even though clients reported crashes. I wonder if it is due to them running 4.1 iOS and the tabs for the crash reports start with the 4.2.x series. Does Apple throw away older iOS reports? We could tell clients to upgrade but we list support as 4.0x and above. Plus upgrading to 5.x series is not for the faint of heart. You darn well better back up everything because I know multiple people that had everything blown away. That was not the case when doing 4.0.x -> 4.1.x -> 4.2.x upgrades and people got a false sense of security. A lot of doctors just get the device and never connect it to a computer. I really don't want to walk them through that process.
Here's hoping the new update is available at the store on Monday!
It is my fault for not catching this earlier. For the test log in we sent to Apple you had three practices to choose from. The bug only occurred on the third practice in the list and only when you pressed the (+) to add a new image to list. Very glad Apple found this issue. I did not want a crash out in the hands of our users and I am sure many would have run into this issue as the layout of the editable items is totally configuration via our administration tool. That tool is not a mobile app but how each client configures what they want the doctor to enter is totally up to them. Annoying this was not caught by QA. As a developer you don't have time to configure piles of test cases in the admin tool then test things out on the mobile side of things. Something like this I should have tested though as it is pretty easy to configure and verify.
It works just fine on the Android. Due to language and GUI component differences the code is not a direct port between the platforms. Could be I was doing a quick conversion to the iPhone or I did the iPhone side first and caught the issue during the Android conversion or the Android code is so different that bug would not occur or I forget to go fix it under iOS post Android conversion. I was back and forth between the two on a daily basis.
Being the sole developer for two platforms is just not easy. I have no one here that can do Objective C code reviews. Someone could look over the Android Java code but I am the only Android developer so some parts of the API would not be familiar too them. Java tends to be Java so I am sure they could find issues if they looked hard enough. Heck, I could find issues if I gave it all a once over. I fixed the issue, ran some tests and we submitted it again.
Within an hour it was back in "In Review" status so Apple obviously saw we got right on the fix and did not move us back to the end of the line. I really did not want our clients to wait another full week for Apple to just start looking at the app again. I am hopeful it gets through the review process in a few hours and we can contact clients starting Monday to let them know a new version is ready that fixes the camera issues and this new issue.
I just got another note from Apple that they need additional review time but they will keep me posted. Must be time for a real test instead of the past two times where it was just shuffled right out into production.
We don't appear to be getting crash reports from Apple. When we look in the crash report section nothing is listed even though clients reported crashes. I wonder if it is due to them running 4.1 iOS and the tabs for the crash reports start with the 4.2.x series. Does Apple throw away older iOS reports? We could tell clients to upgrade but we list support as 4.0x and above. Plus upgrading to 5.x series is not for the faint of heart. You darn well better back up everything because I know multiple people that had everything blown away. That was not the case when doing 4.0.x -> 4.1.x -> 4.2.x upgrades and people got a false sense of security. A lot of doctors just get the device and never connect it to a computer. I really don't want to walk them through that process.
Here's hoping the new update is available at the store on Monday!
Friday, January 13, 2012
Submitted to the app stores today
I have fixed all the client reported issues, a few things I found, a few things QA found and I updated to the new favorite / default favorite processing that works across URL instances and new table loads. It started out being a small thing that got a lot bigger once I dug into what it was going to take to save favorites / reload tables / reload favorites properly across log in sessions. I am very happy with this release and feel good not calling it beta.
The big fix on the Android side was working with slide out keyboards. It was an easy manifest only fix, tracking it down and finding a device to test against were the fun part.
Under iOS the fix was crashing during picture taking due to low memory conditions. I had some bad pairing of create / dealloc between the viewDidLoad and viewDidUnload methods. Once that was straightened out and I was able to get hold of an older iPhone 3GS to test low memory on a device I am pretty darn sure I have this one licked. It did really show me how much Apple has moved forward with the later iOS versions. Before everything was killed instead of being put in the background. If you were mid edit on a case and accidentally hit the Home button to bad. Now the app is in the background and you can get back to it. Something I never had to think about on the Android. I am leaving some of the devices on the old iOS version to remind me of the pain. Plus a lot of users don't upgrade their iDevices because it is not OTA. They never hook it up to their PC. If you upgrade to iOS 5.x you must be careful and backup as it is going to wipe our your data.
Android update is available on the Market now so I can ask the client with the slide out keyboard to test it right away. Hopefully Apple will follow form and have the new release accepted by Sunday and we can have the clients test it starting Monday. They have hit the last couple of releases on the 2 day mark.
In between bug fixes I have been back to working on the JIDE grid based scheduler. I am wrote a custom label for showing the date with the day of the week in a smaller font over the month day, year. I have a pop-up calendar showing when you click on that control allowing you to quickly hop to any date. I added a gradient JPanel I used in some older projects to give the header where the date control lives a nicer look and have started to hook up some of the other buttons. Pretty soon I will move all of this over into the main product and actually load real appointments and display them in the new grid. I need to mess around with the renderer a bit before I do that so it can handle overlapping events and events that only occur in part of the time slot.
It has been fun to work without a device, emulator or simulator. Press and a window just appears and you start testing. Very small proof of concept app so everything loads in an instant allowing you to play around with very little pain. After awhile all apps become huge with features just slowing you down as you are tweaking the GUI. I also don't need to log in as I am not using real data which is also nice. Always good to have a small test harness to piddle around with new programming ideas.
I have Skyrim sitting on my desk, plan to install it tonight along with the patches. There goes this weekend, the next, etc. until the wife and kids don't recognize me.
The big fix on the Android side was working with slide out keyboards. It was an easy manifest only fix, tracking it down and finding a device to test against were the fun part.
Under iOS the fix was crashing during picture taking due to low memory conditions. I had some bad pairing of create / dealloc between the viewDidLoad and viewDidUnload methods. Once that was straightened out and I was able to get hold of an older iPhone 3GS to test low memory on a device I am pretty darn sure I have this one licked. It did really show me how much Apple has moved forward with the later iOS versions. Before everything was killed instead of being put in the background. If you were mid edit on a case and accidentally hit the Home button to bad. Now the app is in the background and you can get back to it. Something I never had to think about on the Android. I am leaving some of the devices on the old iOS version to remind me of the pain. Plus a lot of users don't upgrade their iDevices because it is not OTA. They never hook it up to their PC. If you upgrade to iOS 5.x you must be careful and backup as it is going to wipe our your data.
Android update is available on the Market now so I can ask the client with the slide out keyboard to test it right away. Hopefully Apple will follow form and have the new release accepted by Sunday and we can have the clients test it starting Monday. They have hit the last couple of releases on the 2 day mark.
In between bug fixes I have been back to working on the JIDE grid based scheduler. I am wrote a custom label for showing the date with the day of the week in a smaller font over the month day, year. I have a pop-up calendar showing when you click on that control allowing you to quickly hop to any date. I added a gradient JPanel I used in some older projects to give the header where the date control lives a nicer look and have started to hook up some of the other buttons. Pretty soon I will move all of this over into the main product and actually load real appointments and display them in the new grid. I need to mess around with the renderer a bit before I do that so it can handle overlapping events and events that only occur in part of the time slot.
It has been fun to work without a device, emulator or simulator. Press
I have Skyrim sitting on my desk, plan to install it tonight along with the patches. There goes this weekend, the next, etc. until the wife and kids don't recognize me.
Tuesday, January 10, 2012
Saving database favorites on mobile devices
After a number of missteps I think I have database favorites savings in place on both our Android and iOS applications. How hard can saving favorites be you ask? Much worse than I originally thought for a number of reasons.
With a mobile device a number of things come into play. First there is no log out. As programmers we like symmetry. Open file / close file, log in / log out etc. Matching pairs are awesome. Load when they start, save when the exit, what a beautiful world that would be. You really can't guarantee log in / log out pairing on a desktop application but you have a better shot of it happening. On the mobile side your app can be kicked out due to low memory conditions or the user Task Manager killing it.
My users can log into a specific URL instance then pick the practice which has an associated provider name for their log in name. There are some tables that are static per URL instance, in my case ASA, CPT and Diagnosis, and some tables, which I call session tables, that need to be reloaded per log in. The user wants their favorites and default favorite to carry over between log in sessions and between table reloads from the server.
Between log in sessions the system administrator can add, remove or modify records. That is why we reload things per session. These are generally small tables such as Facilities, Referring Physicians and the like. The large ASA, CPT and Diagnosis tables are updated on a yearly basis. I download a permanent cache table per log in session to see if the ASA, CPT or Diagnosis code table needs to be refreshed even if all my other rules make it look stable. Even when the powers that be decide there are new Diagnosis codes I don't want to lose your list of favorites.
Just after a successful log I check to see if there was a previous successful log in. If there was and the URL is not the same I save all database table favorites to a favorites table if the current database table has at least one row. All tables are loaded on demand meaning I only load them if you need data from them, I don't just load them at start up all while you twiddle your thumbs, that would be a huge waste of time and bandwidth. If the URL is the same but the Practice or Provider is different I save favorites for session tables before I clear them. I don't actually clear the table but I mark it as stale. If during this session a user needs data from that table it will be cleared and reloaded.
Once all that is done I save the URL + Practice + Provider to user settings. That would be NSUserDefaults on iOS and getSharedPreferences on Android. This is the last known good log in. Basically I check for previous session log out during the log in processing. I use the special preferences area on each platform as that is maintained even if the program is ejected from memory or killed by the user. If the user uninstalls the application then all settings are gone and a new install will start the process all over.
In general the ASA, CPT and Diagnosis tables are the same across URL instances but not always. The tables are loaded from the same text file but ProgreSQL does not maintain the same order during record inserts for some reason. We were saving the unique key in the favorites table but now need to save the Code + optional Modifier instead allowing me to match favorites across URL instances. I convert back and forth between ID and Code + Mod as I want to do comparisons on the much faster integer instead of slow string checks once things are up and running.
If you log in to the same URL as the same user and select the same practice every time then I don't save / load favorites to the backing table for the big three. They are just flags set on each table as you toggle the favorite flag on records. The main ASA, CPT and diagnosis tables will only refresh from the server when they get a new master load. Session tables will get a save / load of favorites per log in. It will all be pretty transparent the user. They get a quick busy screen as I load session tables from first time use and after that the data is quickly available for the rest of the log in session.
Keeping it all straight was fun. I need a fully qualified previous log in that I don't touch until all favorite saving is done. I don't want to gut any of the old table data until all favorites have been saved and I have to use backing table data for everything as just saving to the program objects is not persistent enough. When I access the table for favorites saving I need to make sure I don't do any of my stale data checks which would force the table to clear and be repopulated with new data. Post successful log in I don't want to know about the old log in. Tables can be reloaded from the server at any time as the user does an ASA search for example. When the table is stale I need to load it from the server then apply the saved favorites, if any, from the last time they were saved for the current log in URL + Practice + Provider log in. Keep in mind those might have been save 20 log ins ago because the user may have used the ASA table just once in the past 20 sessions even though they logged in over and over.
There can only be one default favorite set per table per unique log in so I have to delete the old before I set the new if we have one.
The best way to handle all of this in testing was to use the emulator for Android and the simulator for iOS. You can't get to the database on a device unless you have a rooted device. Great for security, not so fun for a developer. The emulator in Android is not exactly fast so it made testing less than fun. Plus I have to copy the database file from the device to my hard drive then open it with a third party tool to view the data. I had to log in repeatedly as different users. At last both platforms support the keyboard so I did not have to mouse click on-screen keyboards for the URL, User Name and Password over and over.
The simulator for iOS is faster than the device which is very nice. I use SQLite Manger under FireFox to view the database. The only issue there is anytime you update the simulator you have to track down the database under /Users/{your name}/Library/Application Support/iPhone Simulator/{iOS version}/Applications/{GUID}/Documents/{app}.db and you have to remember to click "All Files" under Format: before you do this as the default is *.sql. If you navigate all the way down the directory path and go "where the heck is my file?" then change to "All Files" you get to navigate all the way down there again which is not user friendly. SQLite Manager remembers the last file opened so you don't have to do this very often. Of course if you test under iOS 3.x, 4.x and 5.x you will have to navigate to each directory for that test. At least the iPhone and iPad share directory for a given iOS version. At first that threw me off, I thought when I switched between iPhone and iPad simulators I would get different data but it loaded up my favorites from the iPhone.
The updated applications are in the hands of QA now. Hopefully I will get them submitted in the next couple of days and go back to my JIDE scheduler table work. It has been a rough couple of days under the old wireless headphones pounding away on both platforms.
With a mobile device a number of things come into play. First there is no log out. As programmers we like symmetry. Open file / close file, log in / log out etc. Matching pairs are awesome. Load when they start, save when the exit, what a beautiful world that would be. You really can't guarantee log in / log out pairing on a desktop application but you have a better shot of it happening. On the mobile side your app can be kicked out due to low memory conditions or the user Task Manager killing it.
My users can log into a specific URL instance then pick the practice which has an associated provider name for their log in name. There are some tables that are static per URL instance, in my case ASA, CPT and Diagnosis, and some tables, which I call session tables, that need to be reloaded per log in. The user wants their favorites and default favorite to carry over between log in sessions and between table reloads from the server.
Between log in sessions the system administrator can add, remove or modify records. That is why we reload things per session. These are generally small tables such as Facilities, Referring Physicians and the like. The large ASA, CPT and Diagnosis tables are updated on a yearly basis. I download a permanent cache table per log in session to see if the ASA, CPT or Diagnosis code table needs to be refreshed even if all my other rules make it look stable. Even when the powers that be decide there are new Diagnosis codes I don't want to lose your list of favorites.
Just after a successful log I check to see if there was a previous successful log in. If there was and the URL is not the same I save all database table favorites to a favorites table if the current database table has at least one row. All tables are loaded on demand meaning I only load them if you need data from them, I don't just load them at start up all while you twiddle your thumbs, that would be a huge waste of time and bandwidth. If the URL is the same but the Practice or Provider is different I save favorites for session tables before I clear them. I don't actually clear the table but I mark it as stale. If during this session a user needs data from that table it will be cleared and reloaded.
Once all that is done I save the URL + Practice + Provider to user settings. That would be NSUserDefaults on iOS and getSharedPreferences on Android. This is the last known good log in. Basically I check for previous session log out during the log in processing. I use the special preferences area on each platform as that is maintained even if the program is ejected from memory or killed by the user. If the user uninstalls the application then all settings are gone and a new install will start the process all over.
In general the ASA, CPT and Diagnosis tables are the same across URL instances but not always. The tables are loaded from the same text file but ProgreSQL does not maintain the same order during record inserts for some reason. We were saving the unique key in the favorites table but now need to save the Code + optional Modifier instead allowing me to match favorites across URL instances. I convert back and forth between ID and Code + Mod as I want to do comparisons on the much faster integer instead of slow string checks once things are up and running.
If you log in to the same URL as the same user and select the same practice every time then I don't save / load favorites to the backing table for the big three. They are just flags set on each table as you toggle the favorite flag on records. The main ASA, CPT and diagnosis tables will only refresh from the server when they get a new master load. Session tables will get a save / load of favorites per log in. It will all be pretty transparent the user. They get a quick busy screen as I load session tables from first time use and after that the data is quickly available for the rest of the log in session.
Keeping it all straight was fun. I need a fully qualified previous log in that I don't touch until all favorite saving is done. I don't want to gut any of the old table data until all favorites have been saved and I have to use backing table data for everything as just saving to the program objects is not persistent enough. When I access the table for favorites saving I need to make sure I don't do any of my stale data checks which would force the table to clear and be repopulated with new data. Post successful log in I don't want to know about the old log in. Tables can be reloaded from the server at any time as the user does an ASA search for example. When the table is stale I need to load it from the server then apply the saved favorites, if any, from the last time they were saved for the current log in URL + Practice + Provider log in. Keep in mind those might have been save 20 log ins ago because the user may have used the ASA table just once in the past 20 sessions even though they logged in over and over.
There can only be one default favorite set per table per unique log in so I have to delete the old before I set the new if we have one.
The best way to handle all of this in testing was to use the emulator for Android and the simulator for iOS. You can't get to the database on a device unless you have a rooted device. Great for security, not so fun for a developer. The emulator in Android is not exactly fast so it made testing less than fun. Plus I have to copy the database file from the device to my hard drive then open it with a third party tool to view the data. I had to log in repeatedly as different users. At last both platforms support the keyboard so I did not have to mouse click on-screen keyboards for the URL, User Name and Password over and over.
The simulator for iOS is faster than the device which is very nice. I use SQLite Manger under FireFox to view the database. The only issue there is anytime you update the simulator you have to track down the database under /Users/{your name}/Library/Application Support/iPhone Simulator/{iOS version}/Applications/{GUID}/Documents/{app}.db and you have to remember to click "All Files" under Format: before you do this as the default is *.sql. If you navigate all the way down the directory path and go "where the heck is my file?" then change to "All Files" you get to navigate all the way down there again which is not user friendly. SQLite Manager remembers the last file opened so you don't have to do this very often. Of course if you test under iOS 3.x, 4.x and 5.x you will have to navigate to each directory for that test. At least the iPhone and iPad share directory for a given iOS version. At first that threw me off, I thought when I switched between iPhone and iPad simulators I would get different data but it loaded up my favorites from the iPhone.
The updated applications are in the hands of QA now. Hopefully I will get them submitted in the next couple of days and go back to my JIDE scheduler table work. It has been a rough couple of days under the old wireless headphones pounding away on both platforms.
Subscribe to:
Posts (Atom)