Sunday, July 7, 2013

How to get apple developer provision profile id

When each time the provision profile is updated in apple developer portal website, downloading the profile will get a new id. If the id does not match, the build will fail because of the signing error saying "the provision profile XXXXXX cannot be found".
However, it seems xcode organizer does not show the profile id for available profiles for identitying the signing error. Neither the Apple developer portal will show this profile id when downloading the profile.
Fortunately, the provision profile id is shown on the iphone configuration tool. So it can be used to find out which profile has which id required by signing.

xcode build settings for debug symbol

Generate debug symbol 
The debug symbol for xcode project is controlled by project settings of "Apple LLVD compiler 4.2"/"generate debug symbol". The recommendation is setting it to YES for both debug and release build. So that it can be used for crash report symbolization.
For application, this will generate a separate dsym file in build output folder. For static library, this will only increase the size of the generated a file

Deployment postprocessing
This is a generic control to decide whether other deployment operation should be performed, particular, Strip Linked Product is executed or not. 
For static library, the recommended setting is NO for both release and debug build, to not remove symbols.
For application build, the recommended setting is Yes for release build and No for debug build. So that release build can have a smaller size.

Strip Debug Symbols During copy
This flag decides when copying the dependent library for building the project, should the library's symbol be removed. It does not affect the build output binary. 
The recommended setting is set to NO for both release and debug build, as the build output needs to include the dependent libraries' symbol to debug or symbolize the library code. 
(It seems for ios project, this setting does not have any effect.)

Strip linked product
This flag will reduce the size of the executable by removing the symbol from it. But it will cause the crash dump not have any symbol, and it will need a separate symbol file to symbolize the crash report.
The flag will not change sym file size.
For library, the recommended setting is NO, so it includes the debug symbol in the .a file
For application, if the app size matters, set it to YES. otherwise, set it to NO.








Friday, July 5, 2013

"Build active architecture only" setting for ios xcode projecgt

When building ios static library, "build active architecture only" does not affect simulator build, it only builds i386 architecture without any armv7 or armv7s build. However, for device build, if it is set to NO. Then all available architecture will be built (armv7 and armv7s); if it is set to YES, then only the active architecture will be built. But how it decide what is the current active architecture? actually, xcode decides it based on build destination, that is, the connected device or simulator type selectedfrom the build type dropdown listbox.
If the current device is armv7s, then it will build armv7s output. If no real device is connected, then it will build armv7 output, which will also support older device types.

Create executable bash script file in mac

Make a txt file to executable script file
1. Use text editor to create the script file
2. right click the file and select "get info"
3. change open with to terminal app
4. run sudo chmod 755 scriptfilename to make it executable by click

Scroll pages in terminal app

To view page up: shift+fn+upArraw or fn+U
To view next down: shift+fn+downArraw or fn+D
to exit, press Q

Tuesday, July 2, 2013

Cordova android create error: "SDK does not have any Build Tools installed."

When running create command on mac to create android cordova project, an error may happen when executing "ant jar". The reason is when updating the Android SDK Tool to  22, somehow the Android SDK build tool was not installed. This can be found from Android SDK Manager, if Android SDK build tool item is not shown under tools item.

Somehow even if running check for update from eclipse does not install it.

To fix the issue run the following command from terminal app.

android update sdk -u

In addition, it is easy to check or change Android SDK manager proxy setting by just running "android" command from terminal.

If you run "create" from phonegap download, then this will not be an issue, as phonegap download already pre-build and install the cordova.jar within the downloaded zip file.

Sunday, June 23, 2013

cordova.js javascript logic

One of the things that makes cordova confuse is it uses the same name for both function parameter and variable.

When cordova.js is called, the outmost function first set the cordova version number and then declare two closure function variables: define and require.
And then it executes another inner function, which implements the define and require function, and modules variable exposed by define.moduleMap.
Up to now, the following variables have been defined inside function scope:
define
require
define.moduleMap
define.remove
When require function is called, it returns the module.exports, which is usually a constructor function to create the module instance. (71:   return modules[id].exports;)

Next, it call define method on cordova and other modules, which will put those modules in modules list. The factory function is not called yet.
define("cordova", function(require, exports, module)...);

define("cordova/argscheck", function(require, exports, module)
define("cordova/channel", function(require, exports, module) 
.....
Then it loads the cordova module with the following line:
window.cordova = require('cordova');
    function build(module) 
    factory:function(require, exports, module). In the factory method, require is the input parameter, container the define function. module is the input parameter represent the current module. exports is the output parameter containing the exported function for the module.
 
The cordova module factory function then load channel by requires it with following code
102: var channel = require('cordova/channel');

For channel:
Note the line 102, var channel = require('cordova/channel');  The var channel contains the exported       javascript object returned to channel.exports. The Channel defined in line
var Channel = function(type, sticky) {
is the prototype construtor for creating an individual channel object, which can handle a particular event
514: var utils = require('cordova/utils'),
After utils module is loaded, channel module register events with the following calls
722: channel.createSticky('onDOMContentLoaded');
725: channel.createSticky('onNativeReady');

107: after channel module is loaded,  cordova module can hookup document event with channel event
186: var cordova = { create the cordova object as exported javascript object
328: expose cordova module by: module.exports = cordova;

6255: (function (context) { call the context method on window object, it will require and load all modules, like contact, and file



 

Saturday, June 22, 2013

cordova ios native code logic

For cordova ios project created by cordova create command, the application and plugin starting up includes the following logic:
1.  AppDelegate
In didFinishLaunchingWithOptions, it initializes MainViewController, which is a subclass of CDVViewController. The init of CDVViewController will hook up cordova function with application.

2. CDVViewController
In CDVViewController, __init method, it first registers all application notification event, so that it can relay those event to javascript. Then it calls loadSettings, which will parse config.xml which defines the cordova behavior, including starting page and plugin definition.
The CDVViewController owns all plugins instance after the instances are created. That is the plugin lives within CDVViewController's scope and lifetime. However, it is possible, the same webview loads multiple html js app, in that case, the plugin's state in native code will not be reset automatically when new page loads. For this reason, CDVPlugin interface defines a method onReset to clean up the plugin state from js page to page. This method should be implemented by each plugin.

The CDViewController has an important method createGapView, which is called in viewDidLoad method. This method creates UIWebView control, and also sets CDVViewDelegate to the UIWebView instance, to handle the page event. The createGapView method also hooks up with javascript request using CDVURLProtocol (a sub class of NSUrlProtocol).  When a javascript method is called,

3. plugin
Usually, plugin will not create its instance until its method is called the first time. But it can also create its instance during ApplicationDidFinishingWithOption by setting onLoad attribute in config.xml. If so,  the PluginInitialize method can be implemented to register the application events including openUrl, etc. Some basic event it registered by its base class CDVPlugin interface, so do not register those event again.
The plugin method is alway called from the main thread.