Categories
iPhone app

5 ways to do the callbacks in objective C and iOS dev

Reading Time: < 1 minute

1. Selector
http://stackoverflow.com/questions/3482344/what-actually-is-a-selector

An example
http://stackoverflow.com/questions/10758926/add-selector-to-uibutton
[button addTarget:yourObject action:@selector(yourMethod:) forControlEvents:UIControlEventTouchUpInside];

2. NSNotifications
In a way (and in syntax too) it’s similar to Selector, but used in different settings.

example here
http://www.cocoanetics.com/2009/08/love-to-be-notified/

3. Delegate methods
e.g., UIAlert view, UITextField delegate

customized method (example)
http://www.raywenderlich.com/29474/ipad-for-iphone-developers-101-in-ios-6-custom-input-view-tutorial

4. Blocks
https://developer.apple.com/library/mac/#featuredarticles/BuildingWithBlocks/_index.html

example
http://stackoverflow.com/questions/7180552/implementing-a-method-taking-a-block-to-use-as-callback

5. GCD
My favorite example here.
http://www.fieryrobot.com/blog/2010/07/10/a-watchdog-timer-in-gcd/

Combinations of some of the above, e.g, blocks (GCD) with notification

Categories
Fun iPhone app

Objective-C code hall of shame

Reading Time: < 1 minute

Today I found out I made a dumb mistake while deleting an NSMutableArray.

for(int ii=0; ii<[myNSMutableArray count]; ii++) { myNSMutableArray removeObjectAtIndex:ii]; } The reason being it will get confused about the elements (index) during the loop. The correct way is to use removeAllObjects method.

Categories
iPhone app Software development

Code signing error in Xcode

Reading Time: 2 minutes

(Update 08-Dec-2020) Things I learned today (or tomorrow am 🙂

  1. One team can have at most two distribution certs
  2. In Xcode sign in as agent without the (mail.com or gmail.com after @) because it appears my apple id is just the id without all the @ + dot com stuff. That alone cost me probably one hour. Plus the one hour I tried to export cert in old MacBook, then move it over to the new MacBook. So totally 2 hours wasted… after those two steps, I was able to go back to automatically signing and validate my archive (ipa) for myNestEgg…

Managing a Distribution Certificate

No signing certificate “iOS Distribution” found

Create, export, and delete signing certificates

====

For organizations, if a distribution certificate is missing a private key or not in your keychain, you can email the creator of the signing certificate. Ask the creator to export the signing certificate on their Mac so you can install it on your Mac. (To install a certificate in your keychain, double-click the exported certificate file.)

====

What is app signing?

Creating the iOS Distribution Certificate

iOS – Creating a Distribution Certificate and .p12 File

(Original 06-Feb-2013) Had my share of code signing problem (esp. the enterprise distribution certificate) in my Xcode development. Luckily, stackoverflow rescued me as always. It seems a lot problem is due to the Xcode upgrade, project name change, provision profile/distribute certificate expiring etc. And the solution is usually delete or comment out the offending line. Like below. To go to the project file, I usually do in the command line, “cd projectName.xcodeproj”, then “vi project.pbxproj”.

http://stackoverflow.com/questions/1760518/codesign-error-provisioning-profile-cannot-be-found-after-deleting-expired-prof

http://stackoverflow.com/questions/5758154/code-sign-error-provisioning-profile-cant-be-found

I encountered another problem related to the provisioning profile expiration, the distribute certificate appears twice in the Keychain, even after I deleted it explicitly. It turns out the old distribute certificate came back after I opened the project in Xcode (presumedly it came back when the old provision profile associated with the project got loaded). So the workaround is to delete the old distribute certificate again after opening the project in Xcode.

http://stackoverflow.com/questions/5932522/codesign-error-certificate-identity-appearing-twice

Btw, saw an interesting idea from Mobile Iron regarding the enterprise distribution certificate. Normally the certificate expires in a year. In last 30 days it will prompt the user something like “the provision profile will expire in a few days…”, not good user experience. There is no way to renew it before it expires either. So the workaround suggested by MI is create 2 certificates, and create the second 6 months before the expiration and have user update the app. This way, essentially the app got extended 6 months. And so on. There is one catch in Xcode 4.3.3 I am using. It only recognizes the provision profile that was created earlier (or expires earlier). The workaround there is delete the earlier provision profile 😀

Categories
iPhone app

Some tips when creating WCF web service for iPad consumption

Reading Time: < 1 minute

Continuation of previous post.

1) WCF get does not like “NULL” column in the query results

2) // note the “id” should match in declaration and method

Categories
iPhone app

Creating WCF web service II

Reading Time: < 1 minute

A continuation of previous post.

1) Visual Studio, publish web service: check destination IIS app
Before the change, the error was “cannot show the content of the folder”.

2) Add this line to the service.cs (service class C# file), to work around/avoid a problem, asp .net compatibility issue. Do something like this:

[ServiceBehavior]
[AspNetCompatibilityRequirements(RequirementsMode=
AspNetCompatibilityRequirementsMode.Allowed)]
class BarService : IHelloContract
{
// …
}

Refer to wenlong

3) Bad request: it appears to be a class rename problem, Visual Studio has a “red” warning sign, follow it and accept “update”, rebuild.

Categories
iPhone app

Two mac tips

Reading Time: < 1 minute

1) This puzzelled me for a while, my macbook air run out of space often. I was trying to use the build “Finder” to find large files, delete files and some unused apps, to no avail. I did some more google and used this Mac App “FindSpace”. And I found this directory /var/vm has some large swap files. Aha. Found the culprit. This article from osxdaily has more explanation.

2) Old Macbook heat. My 3 years old macbook air recently has the problem of overheat. It heated up fairly quickly after using 10 to 15 minutes. Did some google and found this one described my symptom well. The solution appears to be “SMC reset”. I did it yesterday and it works better at least for now…

(01-02-2017) I found chrome can take a lot space too, as well as the iTunes (iPhone) backup file (appears under mobile sync). Also the MacBook Pro retina has similar battery issue (cannot charge), did Smc reset, worked a while. Eventually had to send to Apple Store for a complete fix.

Categories
iPhone app

Three way to create customized input control for UITextField

Reading Time: < 1 minute

Recently I need to create some customized textfield to input numbers and text on iPad. I don’t like the default keyboard on iPad because it takes too much of the screen, and in some cases covers up the input field.

1) From iphonedevsdk: What is proper way to do UITextField text change call back? (this also mentioned by stackoverflow)

[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventTouchDown];

The downside of this approach is: it takes a press (a tap and hold) to trigger the event.

2) InputView
Create a customized view such as this one at raywenderlich, then set the inputView of textfield. I used this approach to create a number pad that used to only input numbers. There is some limit to this approach as well: the location of customized input view is usually fixed, and in my case (a double picker) for text field (table cell), that is not ideal. I was using pop over controller (again raywenderlich), combined with approach 1, the user does not like the “hold”. After I changed to approach 2, the user does not like the fixed location of input view. So I did more research, and eventually I found the following approach that works for me.

One tip: make sure lock the input view, otherwise it will mess up things after iPad rotation.
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}

3) self delegate, UITextFieldDelegate

Make sure do this in viewDidLoad (or other place initialize the text field):
myTextField.delegate = self;

This way I could have both “single tap” and the pop over controller.

Categories
iPhone app

Create .NET WCF Restful web service for iOS

Reading Time: < 1 minute

I need to create a .NET web service consumable by iOS device. Did some research and found out WCF Restful service is the way to go. I used the following examples (tutorials) to construct my web service.

0) Basic Resource Service (link here).
This is basically a self hosting web service run in a main program. A good starting point to learn dataContract, webHttp, etc.

1) I need to change from a console app to a web service, and host on IIS, for this refer to
project 1
and
2(Space Service, a WCF web service app)

2) I need to combine 2 services into one program, and I referred to endPoint.tv plural sight podcast “Building RESTfil services with WCF”

The video above mentioned the httputil.js, HTTP POST/PUT utility, which is handy to test “POST” method. Another tool I used to test GET/POST, is “fiddler”.

A Guide to Designing and Building RESTful Web Services with WCF 3.5, also by Aaron Skonnard, Pluralsight

Essentially here we need to design a scheme (end points) for hosting multiple services.

3) Database connection, I used sql client, which is pretty vanilla.

4) Use pretty path instead of port number (routing service, refer to SimpleREST service again)

Also “code project” example
http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

Categories
iPhone app

Steve Jobs

Reading Time: < 1 minute

Stanford commencement speech (2005)

Macintosh 1984 commercial

Steve Jobs and Bill Gates in 1983 Apple event

My other post on Steve Jobs.

Walt Mossberg on Steve Jobs.

Categories
iPhone app

Did Apple change iTunes App store ranking algorithm lately?

Reading Time: < 1 minute

It looks like it. Obviously my observation could be quite limited. But here is the background, in the good old days, Apple ranks app mostly by the download number in a given amount of time, and the ratings/reviews. So basically the popular the app, the higher the rank. This process could reinforce itself. Apple realized this approach probably has its limitation, one example being a fairly popular app Facebook (by usage) is not ranked the 1st. So Apple changed its algorithm a bit, it not only ranks by the download number, it also monitors the usage. By “usage” I assume Apple measures mostly by network activity, my reasoning being if an app just does its thing locally, Apple has no way to know it.

Also keep in mind the rating and reviews also play a role in the ranking, my understanding is if all things equal, higher rating or favorable reviews will push the rank higher.

More recently, it seems Apple started to give usage more weight. This is just from my own observation, I have 2 little apps, both are standalone (no network features), and one does fairly well last few month, until recent, it totally went down cliff. I did not know why until I did keyword search, in the past, it ranked 2 or 3, not it fell out of top 25. I tried to rescue such as free download for a limited time. After the free period, download number drops back, and this thing fell out top 25 again 🙁

I think from product lifecycle management (PLM) point of view, this app thing is not as good as traditional software revenue model 🙂