Update sqlite database during iOS app update

We all know updating sqlite database on an existing iOS app could be tricky, esp. with any schema (table) changes. In the good old days when I was developing in-house app, I found out the app would crash when I added a column to the sqlite database, after merely updating the app. The problem was, the old database won’t get updated if we don’t explicitly do it during app start-up (after app update). So what did I tell my user to do? Delete the app, and re-install the app. Not the most user-friendly way, and what if the user has some data on it that he/she wants to keep? What if this app have many users?

I had this updating issue in my mind for a while, because one of my apps needs to refresh its data. There are a few ways to do it: 1) Use a web service to get the data; 2) Just update the sqlite database. The former has some limitations: we could get data via web service, but note we still need to manipulate the database if we need to add a column or table (this is same for both approaches). The latter is faster in terms of development. So I decided to do it. I did some research on stackoverflow and found this post as my reference. Here is my implementation, if you are interested. The following is done in viewDidLoad.

Continue reading

stlplace.com was hacked and restored, plus some thoughts

I found out this site was hacked yesterday evening, as I saw the loading of site on Safari was slower than usual. It also shows incorrect theme, more like a plain theme. With the admin link redirect to spammer site. I decided to tackle it right away. I recall about one year ago something similar happened to this site, and google webmaster tool told me about it. I was able to remove the offending files/directories, by following the recommendation set out by google and some other wordpress sites.

This time I made an almost fatal mistake, during deleting some of the files in wp-includes, I accidentally deleted all the useful php files there. Panicked, I used both the website restore tool, and the import feature of wordpress (mojo marketplace), to no avail. The symptom of the problem was I could not login, and it shows blank page when I login via the wp-admin or wp-login.php after taking my credential. And I can only see the pages at uudaddy.com (I could not log in there either).

I filed for help at the hosting company. But I still feel helpless as this site has about 9 years of my blogging and uudaddy.com has my last 4 years of blogs. Fortunately I was able to find this wordpress help page about updating wordpress, and fix internal server error by deactivating the plug-ins. The latter comes only after I gained some web dev experience lately, knowing more about error 500 :-)

So long story short, I was able to restore all the blogs (those two plus my wife’s happy mandarin.com) by the following:
1) Restore .htaccess file to avoid the redirect to spammer page;
2) Restoring the wp-includes and wp-admin page: upload zip file, extract; in the wp-content directory, I renamed plugin directory as plugin.SAV (this way it deactivates all the plugins);
3) Run the wordpress update as soon as I can log in.

I also backed up the MySQL databases for stlplace and uudaddy, and backed up those two blogs to wordpress.com (this one and this one). I understand blogging itself is a declining trend, and it’s probably not easy for small web hosting company to defend against hackers like Google/Amazon/Wordpress do. That’s why I am also evaluating whether to move to wordpress.com or Amazon EC2 (self hosting). It’s a bit emotional decision as I have hosted this site for 9 years, but I need to consider both my time, the cost of hosting, etc. I will make a decision on this shortly. Meanwhile check out the new blogging sites I mentioned above, in which I will blog both about software development and raising kids.

Rockstar developer

I have thought about this topic for a long time. I remember seeing at one place that an exceptional developer can do work usually done by 10 developers. Or in other words, he/she is a rockstar developer.

Besides productivity, I think rockstar developer has the following traits:

1) Willing to share the knowledge with fellow developers, keep in mind we all learn from each other, rockstar can learn from (dare I say) ordinary developer too;

2) Attention to the details and code quality, and other good development practice such as TDD (test driven development), again sharing knowledge is applicable here;

Continue reading

Developer EQ series : 1

Dont’s
Beat up people in code review or interview;

Change other developers’ code without proper communication, or reasoning; worse, making the working code no longer work (sometimes to satisfying the “tests” :-)

Do’s
Learn, learn something everyday;

Acknowledge our own limitations: acknowledge our mistakes if applicable, we all do make mistakes;

In the same token, when we learn something from someone else, show our appreciation;

PS, also came across this piece “assertiveness from developers” by Jeff Atwood (@codinghorror), which I think is excellent. Essentially the point there is be a good developer is not to be a “nice person to everyone”. A good developer uses his/her best judgement, and speaks from his/her own mind, which includes saying something make other stakeholder uncomfortable (as long as it’s fair and honest statement).

And, slightly off topic, this one “Your Company Is Not A Family” from HBR (Harvard Business Review).

Swift might the the language of the future

Apple : the Swift language (unveiled in WWDC on June 2, 2014)

Tutorials
Developing iOS Apps Using Swift Tutorial Part 1 (Jameson Quave)

learnswift.tips

References and reviews
Matt Galloway : Swift Language Highlights: An Objective-C Developer’s Perspective (raywenderlich.com)

The Verge : The Swift effect: Apple’s new programming language means way more iPhone developers and apps

Ray Wenderlich: Swift Cheat Sheet and Quick Reference (raywenderlich.com)

arstechnica.com : A fast look at Swift, Apple’s new programming language

Btw, Jeff Lamarche (twitter: @jeff_lamarche), the author of Beginning iPhone/iOS Development book, already got book offers for the Swift language. At the same time, don’t throw away Objective-C yet (HuffintonPost).

photo-3

Some iTunes App store tips

Avoid the Payload validation error
To shorten the review waiting time. I noticed this recently in my own apps update. The one without warning has much shorter review waiting time. The rationale is App thinks the app may use private API in this scenario (see this explanation on stackoverflow). From personal experience the one with warnings could be in the “wait for review” queue at least one week longer than the one without warning. So clean up the code if we can. Btw, I was able to fix the first one below (it turns out to be a third party function I no longer use). For the second one below, I read it could be related to Facebook SDK (which my app uses), but have NOT been able to solve it for now.

collegeFund_submit_warnings

ToMarket_submit_upload_warn

Validation
Validate before submit to App store, in Xcode organizer.

Keywords
Try put in relevant key words for the app during update (the only time we can change it); we can find some useful keyword by search App store. Also keep in mind search does not work all the time on iPhone. Code Signing
This one is very subtle. I had two certificates, one was used both for dev and distribution; another one was for distribution (Ad hoc or App store). I found initially I could not sign the app by using the distribution certificate (provisioning profile) alone. After back and forth I was able to sign. And as I look at the certificate in Xcode now, it’s refers to the Ad hoc certificate, but in the submission process it still prompts the first one.

    Ads or no ads

    Should I put iAd to my iOS apps on iTunes App store? Should I put the google adsense back to my blog? The reason I am asking this question is: while personally I really don’t like the ads on Facebook, LinkedIn, or the iAds on some apps like Echofon, I understand this is a meaningful way for app developers to make some money. This applies to me as well. While I did not spend whole a lot time working on my apps (in aggregate), I cannot go on this app dev road without any meaningful downloads/income revenue forever. I can do it for a while. But not for too long. I believe Ray Wenderlich talked about the importance of Ad revenue at recent raywenderlich.com podcast. One of the episode of Paul Kemp’s the App Guy Podcast (onemob.com) , talked about something similar.

    I guess, the trick is to balance the ads and app. We don’t want ads to totally destroy the good experience of an app, but at the same time, if the app revenue could help the developer keep going, go for it. We live in a commercial world, no money, no bread. No bread, how can app developers survive?

    photo

    Btw, I found the Apple developer documentation for iAd is insufficient or not up-to-date. For example, it uses requiredContentSizeIdentifiers in the tutorial, which is already deprecated in iOS 6. I found it won’t compile with iOS 7 SDK. I have seen in the past Apple does not always updates its developer documentation. Maybe they have not given high priority to this. I am sure if they pay attention, they can fix it.

      Singleton pattern backfired on me

      This is a continuation of my earlier post of Tree, recursive function and my dumb mistake. As I said in my last post, my solution was to create hash maps (singleton) to store those for the session. The main motivation was to help out the performance. But I found out it backfired on me, a few days ago and today. In both cases, it has to do with the hash map I created, it was something like (object , a list of objects). In both cases the list of objects was actually dynamic, and I made an assumption it was static. In other words, I thought I only need to put the mapping to the map once, then I can use it happily ever after. I think there might be ways to get around it, i.e., I should update the map when that list does change. I will investigate and work on it more. (Update 05-30-14) So I found a solution to one scenario, I was able to update the map as needed. And I use put method (java hashmap) to do that update.

        app development, Java, iOS, mobile app, software development, St. Louis