Thursday, October 23, 2014

change the size of storyboard viewcontroller to match ipad or iphone screen size

By default, the xcode will create viewcontroller in storyboard as a square, and then use constraints to adjust the actual size and control location based on actual device size. However, it may be better to show the actual iphone or ipad size when designing the screen layout.

To resize the storyboard to iphone or ipad screen size, select the storyboard item in project navigator,  then in the property file inspector, uncheck the "Use Auto Layout" and "Use Size Class", when prompting for the screen size, choose iphone or ipad

In addition, the size of view in the viewcontroller in storyboard is readonly, to adjust the view's size, select the viewcontroller item in storyboard, then in viewcontroller's size inspect, change the simulated size from fixed to FreeForm.  Then the view's size will be adjustable.

Settings that affect ios xocde 6 keychain share function

After setting the same key in Keychain Sharing ->Keychain Group in Xcode 6 project Capability setting, the two applications still failed to share the keychain item.
It turns out the below additional settings should also match:
1. in project General settings, Identity Team must be same
2. In project Build Settings, the code signing -> Code Signing identity must be same


Sunday, October 5, 2014

What is new in ios Swift comparing to Objective C

After taking a quick look at iOS swift, from my impression, it does not contain many new concept not seen in C# or Java, it is more like a catch-up to C# or java instead of a new language for developing.

Compare to Objective C, the new things swift provide are:

1. remove the compatible with c, or there is not need to prepend '@' when string is used
2. support optional types
3. support generic in class or method
4. use a single .swift file to define class instead of separate header (.h) file and (.m) implementation file
5. use tuple to return multiple values without defining the multiple output parameters


ios proper way to trust self-signed server certificate

For ios https connection, the proper way to trust self signed server certificate is to install the root CA certificate (which signs the server certificate) to device profile using MDM or iPhone configuration tool, in that way, the self-signed root certificate will be used by all ios applications on device, and it is handled transparently to the application logic.

Note, simple accept and trust the self-signed certificate on a https web page from Mobile Safari is not enough, as that will only let Safaria accepts the self-signed certificate, and does not install the certificate into device profile, so the other applications will still not trust this self-signed certificate, and fails to establish the https connection with it.

As another option, if a self signed certificate only needs to be trusted by a single application, and you have the full control of the implementation of this application, that is, the application does not use other third party library to establish https network connection, then you can also include a copy of the root certificate into the application bundle and then call SecCertificateCreateWithData and SecTrustSetAnchorCertificates to trust the self-signed certificate. Note usually you will want to trust both the build-in device root CAs and the self-signed root CA, if so, you should also call SecTrustSetAnchorCertificatesOnly with false parameter, so that both of them will be evaluated by a single call to SecTrustEvaluate.

In addition, if you handle the self-signed certificate by your application, you can get the server certificate and its root certificate information from challenge.protectionSpace.serverTrust object by calling the below code. This information can be used to prompt users to decide whether to trust this self signed certificate or not.

        SecTrustRef trust =  challenge.protectionSpace.serverTrust;
        long certCount = SecTrustGetCertificateCount(trust);
        for (int certIndex = 0; certIndex < certCount; certIndex++) {
            SecCertificateRef   thisCertificate;
            
            thisCertificate = SecTrustGetCertificateAtIndex(trust, certIndex);
            NSString* summary = (__bridge NSString *)(SecCertificateCopySubjectSummary ( thisCertificate ));
            NSLog(@"%@", summary);

            //get DER representation of the certificate data and parse it with openssl library
            CFDataRef certData = SecCertificateCopyData ( thisCertificate );
       //... parse the certificate data with OpenSSL library
       //... prompt user with the certificate information
       CFRelease(cerData);

        }

Thursday, October 2, 2014

Difference between Apple Configurator and iPhone Configuration Utility

Apple Configurator and iPhone configuration Utility provide the similar function, but are used for different purpose.

iPhone Configuration Utility is available for both Windows and Mac OS, it is mainly for developer or advanced ios user, to install or remove app, or configure the device setting. One major usage is installing self-signed server root certificate for https connection. The installed root certificate can be used by both mobile safari and client application when establishing https connection. It can also be used to install client certificate (p12) for mutual authentication, but the installed client certificate can only be used by mobile safari and is not accessible by client application.

Apple Configurator is only available for Mac OS, it provides additional function than iPhone Configuration Utility, but it is more complex to use. It is mainly for small business or organization to manage and monitor multiple devices for multiple users as an alternative to other MDM system, so that users can share the same device but keep their own data when using it. Besides the profile and configuration management, it also provides functions of backup and restore per user account, iOS version update. For developers, if you only need to use it to install a profile to a single device, you can still do from "Prepare->Settings->Profile->Install Profiles..." menu, without putting the device under Supervise control.

Both tools do not provide the function of configure the individual application through NSUserDefault change listener as regular MDM server does.