<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iCab Blog &#187; iCab</title>
	<atom:link href="http://www.icab.de/blog/category/icab/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.icab.de/blog</link>
	<description>iCab related stuff; Mac, iPhone and Cocoa programming</description>
	<lastBuildDate>Mon, 17 Oct 2011 15:03:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>iCab Mobile Modules and Apple</title>
		<link>http://www.icab.de/blog/2011/03/26/modules-for-icab-mobile-and-apple/</link>
		<comments>http://www.icab.de/blog/2011/03/26/modules-for-icab-mobile-and-apple/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 23:46:55 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[iCab]]></category>
		<category><![CDATA[iPhone & iPod Touch]]></category>
		<category><![CDATA[iCab Mobile]]></category>
		<category><![CDATA[modules]]></category>

		<guid isPermaLink="false">http://www.icab.de/blog/?p=190</guid>
		<description><![CDATA[Recently I received a phone call from Apple. They asked me to remove the ability to download and install modules from the internet in iCab Mobile. So as of iCab Mobile 4.6, the ability to download and install modules is no longer working. But the modules feature is not gone. I&#8217;ve simply included all modules [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I received a phone call from Apple. They asked me to remove the ability to download and install modules from the internet in iCab Mobile. So as of iCab Mobile 4.6, the ability to download and install modules is no longer working.</p>
<p>But the modules feature is not gone. I&#8217;ve simply included all modules which could be downloaded before from my server directly in iCab Mobile, so all the modules are automatically available without downloading them before. So for most users nothing serious has changed.</p>
<p>The only problem is with the modules (written by users) which I don&#8217;t know of. Users can no longer write and share their own modules themselves. If you know of such a module or if you still want to write a module, please contact me. I can add these modules to the next updates of iCab Mobile and this way the modules can be still shared with all iCab Mobile users.</p>
<p>I really can&#8217;t say that I like Apple&#8217;s decision, and technically it doesn&#8217;t make much sense.  &#8221;Modules&#8221; for iCab Mobile are simply a more comfortable variation of bookmarklets, and these are still allowed by Apple (and I assume Apple can not forbid that the user will save and use bookmarklets). Maybe if I would have called the modules &#8220;smart bookmarks&#8221; and would have made installing them much more complicated, Apple would have never asked to remove the ability to download them from the internet. The great user experience of installing modules has probably created a suspicion that these modules are more than just a piece of JavaScript code. From a pure technical point of view, if Apple does not allow to download modules (JavaScript code), Apple would also have to disallow to load web pages in general, because these do also contain JavaScript code.</p>
<p>I think the current solution in shipping all modules together with iCab Mobile should be fine for all users and should not cause much trouble. Hopefully one day Apple will rethink their decision and will allow module downloads and also some other stuff again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icab.de/blog/2011/03/26/modules-for-icab-mobile-and-apple/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
		<item>
		<title>Changing the headers for UIWebKit HTTP requests</title>
		<link>http://www.icab.de/blog/2010/04/07/changing-the-headers-for-uiwebkit-http-requests/</link>
		<comments>http://www.icab.de/blog/2010/04/07/changing-the-headers-for-uiwebkit-http-requests/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 15:51:58 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[iCab]]></category>
		<category><![CDATA[iPhone & iPod Touch]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iCab Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[WebKit]]></category>

		<guid isPermaLink="false">http://www.icab.de/blog/?p=144</guid>
		<description><![CDATA[I was asked several times, in which way the &#8220;User-Agent&#8221; header can be modified for the HTTP requests that are initiated from within the UIWebView object. iCabMobile is doing this, and also some other iPhone Apps, but the UIWebView API doesn&#8217;t provide anything which allows to modify the &#8220;User-Agent&#8221; information or any other HTTP header. [...]]]></description>
			<content:encoded><![CDATA[<p>I was asked several times, in which way the &#8220;User-Agent&#8221; header can be modified for the HTTP requests that are initiated from within the UIWebView object. iCabMobile is doing this, and also some other iPhone Apps, but the UIWebView API doesn&#8217;t provide anything which allows to modify the &#8220;User-Agent&#8221; information or any other HTTP header.</p>
<p>When you load a web page from the internet through UIWebView, you can provide a delegate which is called for each web page that is loaded. And in the method &#8220;webView:shouldStartLoadWithRequest:navigationType:&#8221; of the delegate, you&#8217;ll even get an NSURLRequest object you can look at, but unfortunately you can not modify this object. So there&#8217;s no way to change the default &#8220;User-Agent&#8221; information that is sent to the server, nor can you modify any other data.</p>
<p>When you&#8217;re loading data from the internet outside of UIWebView, you would probably use the NSURLConnection class. In this case you would create an NSURLRequest object (or the mutable counterpart NSMutableURLRequest) with all the HTTP headers for the request yourself (using the method &#8220;setValue:forHTTPHeaderField:&#8221;). You have full control over all of the HTTP headers you want to send to the server, including the &#8220;User-Agent&#8221; information.</p>
<p>When we assume that the UIWebView object will internally also use NSURLRequest or NSMutableURLRequest to create a HTTP request before this request is passed to the networking classes like NSURLConnection, we need a way to subclass or overwrite the method &#8220;setValue:forHTTPHeaderField:&#8221; of the NSMutableURLRequest class. Then we would be able to check for each HTTP header that is set for a NSMutableURLRequest, if this is the &#8220;User-Agent&#8221; header and if it is, we can modify it.</p>
<p>The only problem is that we can&#8217;t overwrite or subclass the NSMutableURLRequest class and force UIWebView to use our subclass instead of the original class. But iPhone Apps are written in Objective C and this programming language does allow exchanging and modifying classes, methods, variables etc. at runtime any time. So we can tell the Objective C runtime system that each time the method &#8220;setValue:forHTTPHeaderField:&#8221; of the &#8220;NSMutableURLRequest&#8221; class is called, our own method is called instead. This way it doesn&#8217;t matter that UIWebView will never call our method directly. Exchanging methods is called &#8220;Method Swizzling&#8221; and you can learn more about it on the <a href="http://www.cocoadev.com/index.pl?MethodSwizzling">CocoaDev page</a>.</p>
<p><b>The method swizzling is very powerful, but it can be also very dangerous if you don&#8217;t know what you&#8217;re doing. So be very careful.</b></p>
<p>Now to the sources. I&#8217;ve implemented the method swizzling as a category of NSObject, so you can use it for all classes very easy (but as I said above, be careful, don&#8217;t use it if there are other options).</p>
<p><span style="color: #993300;">MethodSwizzling.h:</span></p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">@interface NSObject (Swizzle)

+ (BOOL)swizzleMethod:(SEL)origSelector withMethod:(SEL)newSelector;

@end</pre>
<p><span style="color: #993300;">MethodSwizzling.m:</span></p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">#import "MethodSwizzling.h"

@implementation NSObject (Swizzle)

+ (BOOL)swizzleMethod:(SEL)origSelector withMethod:(SEL)newSelector
{
    Method origMethod = class_getInstanceMethod(self, origSelector);
    Method newMethod = class_getInstanceMethod(self, newSelector);

    if (origMethod &amp;&amp; newMethod) {
        if (class_addMethod(self, origSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
            class_replaceMethod(self, newSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
        } else {
            method_exchangeImplementations(origMethod, newMethod);
        }
        return YES;
    }
    return NO;
}

@end</pre>
<p>You can call &#8220;swizzleMethod:&#8221; for an object, passing in the selectors of the original and the new replacement methods. If the &#8220;swizzleMethod:&#8221; method returns with the result YES, each call of the original method will then call the replacement method and each call of the replacement method will call the original method. So within your replacement method you can still call the original method.</p>
<p>Here&#8217;s the implementation of the new replacement method for the NSMutableURLRequest class:</p>
<p><span style="color: #993300;">MyMutableURLRequest.h:</span></p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">@interface NSMutableURLRequest (MyMutableURLRequest)

+ (void)setupUserAgentOverwrite;

@end</pre>
<p><span style="color: #993300;">MyMutableURLRequest.m:</span></p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">#import "MyMutableURLRequest.h"
#import "MethodSwizzling.h"

@implementation NSMutableURLRequest (MyMutableURLRequest)

- (void)newSetValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
{
    if ([field isEqualToString:@"User-Agent"]) {
        value = @"The new User-Agent string";
    }
    [self newSetValue:value forHTTPHeaderField:field];
}

+ (void)setupUserAgentOverwrite
{
    [self swizzleMethod:@selector(setValue:forHTTPHeaderField:)
            withMethod:@selector(newSetValue:forHTTPHeaderField:)];
}

@end</pre>
<p>This new method is implemented as a category, we don&#8217;t need to subclass. The replacement method for &#8220;setValue:forHTTPHeaderField:&#8221; is called &#8220;newSetValue:forHTTPHeaderField:&#8221; and it is simply checking if the &#8220;field&#8221; variable is equal to &#8220;User-Agent&#8221;. If it is, the value is modified. Afterwards the original method is called.<br />
Please note: because the method swizzling exchanges the original and replacement methods, we have to call &#8220;newSetValue:forHTTPHeaderField:&#8221; to call the original method &#8220;setValue:forHTTPHeaderField:&#8221;. This looks confusing, but this is the way you can give control back to the original method.</p>
<p>The method &#8220;setupUserAgentOverwrite&#8221; has to be called once after the App is launched (for example in the Application delegate in the &#8220;applicationDidFinishLaunching:&#8221; method, or even in &#8220;main()&#8221;).</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">   [NSMutableURLRequest setupUserAgentOverwrite];</pre>
<p>This should be done before any UIWebView objects are created to make sure that the &#8220;User-Agent&#8221; is modified for all requests.</p>
<p>You can also use this approach when you need to modify other HTTP headers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icab.de/blog/2010/04/07/changing-the-headers-for-uiwebkit-http-requests/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>Modules for iCab Mobile (Updated 2011/03/26)</title>
		<link>http://www.icab.de/blog/2010/02/17/modules-for-icab-mobile/</link>
		<comments>http://www.icab.de/blog/2010/02/17/modules-for-icab-mobile/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 21:39:38 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[iCab]]></category>
		<category><![CDATA[iPhone & iPod Touch]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iCab Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Module]]></category>
		<category><![CDATA[modules]]></category>

		<guid isPermaLink="false">http://www.icab.de/blog/?p=118</guid>
		<description><![CDATA[Update 2011/03/26 Please also read the blog post &#8220;iCab Mobile Modules and Apple&#8221; for recent events, affecting the modules feature. The version 2.1 of iCab Mobile introduces a new &#8220;modules&#8221; feature. Modules make it possible to add new features in iCab Mobile just by downloading them. They can be used for simple things like increasing the font [...]]]></description>
			<content:encoded><![CDATA[<div style="background-color: #fee; padding: 1em;"><strong>Update 2011/03/26</strong><br />
Please also read the blog post &#8220;<a href="http://www.icab.de/blog/2011/03/26/modules-for-icab-mobile-and-apple/">iCab Mobile Modules and Apple</a>&#8221; for recent events, affecting the modules feature.</div>
<p>
The version 2.1 of iCab Mobile introduces a new &#8220;modules&#8221; feature. Modules make it possible to add new features in iCab Mobile just by downloading them. They can be used for simple things like increasing the font size so a page is more easy to read on the small iPhone screen, but also more complex tasks can be done, like downloading YouTube videos or to post a web page URL at Twitter (including the login and creating a tiny URL). iCab Mobile 2.1 comes with a few built-in modules, and there are also several modules available for download.</p>
<p>This blog post will explain, how you can write your own modules for iCab Mobile and how you (and maybe other users) can install them in iCab Mobile.</p>
<h2>Technical background</h2>
<p>Technically, modules are somehow similar to bookmarklets, but with more features and more flexibility. This means the modules are written in JavaScript code and they can do everything that can be done with JavaScript. Unlike bookmarklets, where the complete JavaScript code must be squeezed in one single line so that it can be used as a URL with &#8220;javascript&#8221; scheme, the modules can be nicely formatted, without any line limitation. Modules have a special header section where the module properties are defined. The properties include an icon that is displayed in the Modules panel of iCab Mobile, but also settings which do allow the user to configure the module in the iCab Mobile module settings panel.</p>
<h2>The module structure</h2>
<p>The module is a normal text file with JavaScript code. There&#8217;s a header section and the code section. Here&#8217;s an example, how this looks like:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//startconfig
//id=de.icab.crazy
//icon=iVBORw0KGgoAAAANSUhEUgAAACwAAAAkCAYAAADy19hsAAAWrGlDQ1BJQ0...
//title=Crazy Layout
//description=The module sets random colors for the page elements
//description.de=Das Modul setzt alle Farben der Seite auf Zufallswerte
//var=confirmation;type=confirmation;default=false;
//var=language;type=language;
//endconfig

var hex = "0123456789abcdef";

function iCabMobileGoCrazyForElement(element) {
  if (element.nodeType == 1) {
    if (element.style.display != "none" &amp;&amp;
           element.nodeName.toLowerCase() != 'select') {
      element.style.backgroundColor = "#" +
                   hex.charAt(Math.random()*16) +
                   hex.charAt(Math.random()*16) +
                   hex.charAt(Math.random()*16);
      element.style.color = "#" +
                  hex.charAt(Math.random()*16) +
                  hex.charAt(Math.random()*16) +
                  hex.charAt(Math.random()*16);
      for (var i=0; i&lt;element.childNodes.length; i++) {
        iCabMobileGoCrazyForElement(element.childNodes[i]);
      }
    }
  }
}

var doAction = (confirmation == false);

if (confirmation) {
  var text = "Go crazy?";
  doAction = confirm(text);
}

if (doAction) {
  iCabMobileGoCrazyForElement(window.document.body);
}</pre>
<p>The header section defines the properties of the module. The header section starts with the line</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//startconfig</pre>
<p>and ends with the line</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//endconfig</pre>
<p>Between these two lines all the properties are defined, each individual property definition occupies exactly one line, so currently you can&#8217;t split the definition of a property into multiple lines. Also no empty lines are allowed in the header section. Each property definition has the following format:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//property=value;additional paramaters</pre>
<p>The additional parameters are optional and not always needed or required.</p>
<p>There are some properties which are required. If they are missing, iCab Mobile will ignore the module. Other properties are optional and do not need to be present. Here are the properties which are currently supported:</p>
<dl>
<dt><strong>id</strong> (required) </dt>
<dd>This property identifies the module. When updating or reinstalling a module, the value of the &#8220;id&#8221; will be used to find the old module that has to be replaced by the new one. So when updating a module, you must not change the value of the &#8220;id&#8221;. Everything else can be modified, even the name of the module. The value of the &#8220;id&#8221; property should be unique among all existing modules. The best way to find a good &#8220;id&#8221; value is to use a reverse domain name appended with the module name. If your own web page has the domain &#8220;www.your-domain.com&#8221; you should set the &#8220;id&#8221; value to &#8220;com.your-domain.moduleName&#8221;. All of your own modules will have the same reverse domain prefix and the module name as suffix. If you don&#8217;t have your own domain, you can use your name and city as a prefix and maybe some random numbers, anything which makes it unlikely that someone else uses the same id value. The &#8220;id&#8221; is not visible to the user within iCab Mobile. Its only used to identify the module.<br />
Example:&nbsp;</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//id=de.icab.crazy</pre>
<p>or if you don&#8217;t have your own domain, you may use something like this:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//id=de.darmstadt.clauss.alexander.crazy</pre>
</dd>
<dt><strong>title</strong> (required)</dt>
<dd>The title defines the name of the module and is displayed within the modules settings of iCab mobile. The title property is needed so that the user can enable or disable the modules in the in-app settings and also configure the modules settings.<br />
Example:&nbsp;</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//title=Crazy Colors</pre>
<p>You can also define localized versions of the title. Just append the language code (for example &#8220;en&#8221; for English, &#8220;de&#8221; for German, &#8220;it&#8221; for Italian etc.) of any of the languages which are supported by the iPhone OS to the &#8220;title&#8221; keyword<br />
like this:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//title.de=Verrückte Farben</pre>
<p>This way you can easily localize the module in many languages. The key &#8220;title&#8221; without a language code appended will be used as default language which is used when none of the defined languages does match the current language of the iPhone or iPod Touch. In general the default language should be English. If no default language is defined, then the very first language that is define will be used as default language. But it is highly recommended, that you simply use English as the default language (without language code).</p>
<p>So if the module supports English and German, the title would be defined this way:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//title=Crazy Colors
//title.de=Verrückte Farben</pre>
</dd>
<dt><strong>description</strong> (optional)</dt>
<dd>The description is displayed in the settings panel of the module in iCab Mobile. The description should explain what the module is doing. Localizing is done in the same way as described above for the title. Append the language code to the &#8220;description&#8221; keyword:&nbsp;</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//description=The module sets random colors for the page elements
//description.de=Das Modul setzt alle Farben der Seite auf Zufallswerte</pre>
</dd>
<dt><strong>icon</strong> (optional, but highly recommended)</dt>
<dd>The icon is displayed when the user opens the modules panel where the modules can be activated by tapping on their icon. The icon should be an image file in PNG or JPG format. The data of the image file must be encoded with &#8220;base64&#8243; and this &#8220;base64&#8243; encoded data can be then used as value for the &#8220;icon&#8221; property. Usually the base64 data is formatted in lines of at most 64 characters length, but for the modules, all line breaks must be removed, so the icons data can be completely included in one line. The size of the module icons (the visible part) should be approx. 41*32. You can use the following empty icon image as a template for your own icons:<br />
<a href="http://www.icab.de/img/empty.png"><img src="http://www.icab.de/img/empty.png" alt="" /></a>&nbsp;</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//icon=iVBORw0KGgoAAAANSUhEUgAAACwAAAAkCAYAAADy19hsAAAWrGlDQ1BJQ0...</pre>
</dd>
<dt><strong>var</strong></dt>
<dd>The &#8220;var&#8221; property defines JavaScript variables, which are initialized by iCab Mobile. These variables can be used to allow the user to configure the modules, but also to get certain system properties, like the system language.&nbsp;</p>
<p>Variables do have the following format:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//var=NameOfVar;type=typeOfVar;default=defaultValue;title=labelForSettings;</pre>
<p>iCab Mobile will create a standard JavaScript variable declaration and initialization for all of these variable properties and adds these to the JavaScript code of the module. So your JavaScript code of the module can check and use these variables just like any other variables.</p>
<p>The value of the &#8220;var&#8221; property is the name of the variable.</p>
<p>The &#8220;title&#8221; property is required, when the variable should be presented to the user in the module settings, so the user can change the value of the variable. The value of the &#8220;title&#8221; property is used as the label in the settings panel. You can add additional localized versions of the title, just by appending the language code (as described above).</p>
<p>The &#8220;default&#8221; property can be used to define a certain default value for the variable.</p>
<p>The value of the &#8220;type&#8221; property is the type of the variable, which can be one of the following:</p>
<dl>
<dt><strong>bool</strong> or <strong>boolean</strong></dt>
<dd>The variable can have the values <strong>true</strong> or <strong>false</strong>. In the module settings this variable will be represented by a &#8220;switch&#8221; control. If the user switches it on, the variable will have the value  <strong>true</strong> otherwise the variable will have the value <strong>false</strong>. The title attribute is required for this type. The title is shown as label for the switch in the module settings. </dd>
<dt><strong>int</strong> or <strong>integer</strong></dt>
<dd>The variable can have a numerical value. In the module settings, this variable is represented with a text field where you can enter digits. The title attribute is required for this type. The title is shown as label for the edit field in the module settings. </dd>
<dt><strong>string</strong> or <strong>text</strong></dt>
<dd>The variable can have a string value. In the module settings, it is represented as a text field. The title attribute is required for this type. The title is shown as label for the edit field in the module settings. </dd>
<dt><strong>pass</strong> or <strong>password</strong></dt>
<dd>The variable can have a string value. In the module settings, it is represented as a text field where the input is hidden. The title attribute is required for this type. The title is shown as label for the edit field in the module settings. </dd>
<dt><strong>lang</strong> or <strong>language</strong></dt>
<dd>The value of this variable is a string that contains the language code of the currently selected system language. This variable is not presented in the settings panel of the module. Therefore no title property is required here. </dd>
<dt><strong>confirm</strong> or <strong>confirmation</strong></dt>
<dd>The variable has a boolean value. It is represented in the module settings by a switch where the user can enable or disable a confirmation box. If enabled, iCab Mobile will ask each time the module is activated, if it should be really executed. This variable does not need a &#8220;title&#8221; property because it is automatically localized within the module settings panel. </dd>
<dt><strong>autorun</strong></dt>
<dd>The variable has a boolean value. It is represented in the module settings by a switch where the user can configure, if the module should be automatically run when the page has finished loading. This variable does not need a &#8220;title&#8221; property because it is automatically localized within the module settings panel. If there&#8217;s no variable of the type &#8220;autorun&#8221; set, the module can only be opened manually. You can set the  default value for the variable to switch on or off the &#8220;autorun&#8221; feature for the module. But the user will be always able to disable the &#8220;autorun&#8221; feature in the module settings. When the modul is executed, the variable that is defined with the type &#8220;autorun&#8221; will have the value &#8220;true&#8221; if the module was executed automatically (which means when the page has finished loading) and the value &#8220;false&#8221; if the module was opened manually by the user. So a module is able to do different thing when called automatically and when called manually (for example it can mark elements when called automatically to notify the user about something, and modify the elements when called manually, to do the real work). [This feature will be available in iCab Mobile 3.3, it's not yet available in version 3.2]</dd>
<dt><strong>select</strong></dt>
<dd>The variable of this type can be used to select one item from an array of items. This variable type uses the title property in the same way as the other types to define the label in the module settings. This variable type requires that two other properties are defined as well. The &#8220;values&#8221; property must be defined to create the array of values the user can choose from, and the &#8220;valuetitles&#8221; property must be defined to define the array of titles for these values. The &#8220;valuetitles&#8221; properties is localizable again, so append the language code as shown above for the &#8220;title&#8221; property. For the &#8220;values&#8221; and &#8220;valuetitles&#8221; property, all items must be separated by the &#8220;|&#8221; character.<br />
An example:&nbsp;</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//var=s;type=select;valuetitles=One|Two|Three;values=1|2|3;title=Number;default=2</pre>
<p>In the settings the user would be able to choose between &#8220;One&#8221;, &#8220;Two&#8221; and &#8220;Three&#8221;. If the user selects &#8220;One&#8221; the variable <strong>s</strong> would have the value <strong>1</strong>, if the user selects &#8220;Two&#8221; the variable <strong>s</strong> would have the value <strong>2</strong> etc. The default value would be <strong>2</strong> and the user would see that &#8220;Two&#8221; is preselected. The whole setting would have the label &#8220;Number&#8221;.</p>
</dd>
</dl>
<p>When the user activates a module, iCab Mobile will process the header sections and creates JavaScript variable declarations for all the variable definitions from the header section. The values for these variables will be determined by the module settings. Technically, iCab will add these variable declarations before the JavaScript code section of the module, so the module can access these variables. These variables and the JavaScript code section will be embedded in a block, so they have their own scope and do not interfere with the JavaScript code and variables which are already present in the web page.</p>
<p>This means, when the module looks like this:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">//startconfig
//id=de.icab.module
//icon=iVBORw0KGgoAAAANSUhEUgAAACwAAAAkCAYAAADy19hsAAAWrGlDQ1BJQ0...
//title=Some Module
//var=confirmation;type=confirmation;default=false;
//var=language;type=language;
//var=text;type=string;title=Text;
//endconfig

function DoSomething() {
  // here's the actual code which is doing all the work of the module
}

if (confirmation) {
  doAction = confirm("Really activate the module?");
} else {
  doAction = true;
}

if (doAction) {
  DoSomething();
}</pre>
<p>the resulting code that is actually executed in the context of the web page looks like this:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">{
  var confirmation = true;
  var language = "en";
  var text = "User Input";

  function DoSomething() {
    // here's the actual code which is doing all the work
  }

  if (confirmation) {
    doAction = confirm("Really activate the module?");
  } else {
    doAction = true;
  }

  if (doAction) {
    DoSomething();
  }
}</pre>
</dd>
</dl>
<h2>Special JavaScript functions</h2>
<p>Modules can also call special JavaScript functions, which are defined by iCab Mobile to do certain tasks.</p>
<p>There are the following functions available:</p>
<dl>
<dt><span style="font-family: monospace; color: #003300; font-size: 0.9em;">startDownload(url,file)</span> </dt>
<dd>This function starts a download. The parameters are the URL and a suggestion<br />
for the filename under which the download should be saved. </dd>
<dt><span style="font-family: monospace; color: #003300; font-size: 0.9em;">postRequest(url,content,&#8221;callBackFunction&#8221;)</span> </dt>
<dd>This function gets the data from the URL using the HTTP POST command (posting &#8220;content&#8221; to the server) and then passes the HTTP status code and the data to a function called &#8220;callBackFunction&#8221; (see getRequest() below for a description of the callback function).</dd>
<dt><span style="font-family: monospace; color: #003300; font-size: 0.9em;">getRequest(url,&#8221;callBackFunction&#8221;)</span></dt>
<dd>This function gets the data from the URL using the HTTP GET command and then passes the HTTP status code and the data to a function called &#8220;callBackFunction&#8221; (the second parameter is a string with the name of the callback function that must be implemented by the Module to process the data):&nbsp;</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">function callBackFunction(status, data) {
  // "status" is an integer value with the HTTP status code (200, 404, etc)
  // "data" is a string with the URL data
}</pre>
</dd>
</dl>
<h2>Installing the modules</h2>
<p>Installing the modules is done by simply downloading them from a web site. So all you need to do is to provide a web page which contains a link to your module. The link URL must use the URL scheme &#8220;icabmodule&#8221; or &#8220;javascriptmodule&#8221; instead of the usual &#8220;http&#8221; scheme. This is how iCab Mobile detects that it should download and install a module.</p>
<p>For example, if your module can be accessed with the URL <strong>http://your.webspace.com/modules/TheModule.icabmodule</strong><br />
the HTML link you would have to include in your web page would look like this:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">&lt;a href="icabmodule://your.webspace.com/modules/TheModule.icabmodule"&gt;Download TheModule&lt;/a&gt;</pre>
<p>or alternatively look like this:</p>
<pre style="padding-left: 0.7em; border-left: 1px solid #030; color: #003300; font-size: 0.9em;">&lt;a href="javascriptmodule://your.webspace.com/modules/TheModule.icabmodule"&gt;Download TheModule&lt;/a&gt;</pre>
<p>If you include these links on a web page which is accessible to other people as well, other iCab Mobile users would be also able to install your module. So you can easily share your modules with other users.</p>
<p>I&#8217;ve created two URL schemes for the modules. In case other iPhone developers are interested in this module feature (candidates would be developers of other iPhone browsers),  it would be great if all these modules would be compatible. In this case the general URL scheme &#8220;javascriptmodule&#8221; could be used by all the Apps supporting the modules feature. And the other URL scheme could be used for application specific-modules (so &#8220;icabmodule&#8221; would be only accepted by iCab Mobile).<br />
Just a reminder: My <a href="http://www.icab.de/blog/2009/09/12/applink-for-the-iphone/">AppLink Proposal</a> can be also used by other iPhone Apps.</p>
<p>You can also sent the module to <a href="mailto:alexander@icab.de">me</a> so I can include it into the modules download page, which is accessible through the &#8220;Download&#8221; module that is built-in in iCab Mobile. This way the module can be immediately found by all iCab Mobile users.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icab.de/blog/2010/02/17/modules-for-icab-mobile/feed/</wfw:commentRss>
		<slash:comments>101</slash:comments>
		</item>
		<item>
		<title>&#8220;AppLink&#8221; for the iPhone.</title>
		<link>http://www.icab.de/blog/2009/09/12/applink-for-the-iphone/</link>
		<comments>http://www.icab.de/blog/2009/09/12/applink-for-the-iphone/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 22:07:46 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[iCab]]></category>
		<category><![CDATA[iPhone & iPod Touch]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iCab Mobile]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.icab.de/blog/?p=60</guid>
		<description><![CDATA[I&#8217;ve now updated the proposal I&#8217;ve introduced with the blog post &#8220;Calling alternate browsers on the iPhone&#8221; a few weeks ago. The new implementation is now named &#8220;AppLink&#8221; (thanks to Robert Chin for the name &#8220;AppLink&#8221;) and is much more powerful. The main purpose of AppLink is to make it possible for (internet-aware) iPhone Apps [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve now updated the proposal I&#8217;ve introduced with the blog post &#8220;<a href="http://www.icab.de/blog/2009/08/04/calling-alternate-browsers-on-the-iphone/">Calling alternate browsers on the iPhone</a>&#8221; a few weeks ago. The new implementation is now named &#8220;<strong>AppLink</strong>&#8221; (thanks to Robert Chin for the name &#8220;AppLink&#8221;) and is much more powerful.</p>
<p>The main purpose of AppLink is to make it possible for (internet-aware) iPhone Apps to call each other to open certain URLs. For example by default, all apps are able to let the iPhone OS open a URL, and the iPhone OS will launch Safari or Mail to open these URLs. Unfortunately the iPhone OS will never call other apps (like an alternate Web Browser) for the standard URL schemes, so you can&#8217;t change the default browser or the default Mail app.  If Apps support non-standard URL schemes then the iPhone OS is able to call these Apps from within other Apps, but the problem is, that the other Apps don&#8217;t know about these non-standard URL schemes. So calling these apps is difficult.</p>
<p>AppLink will try to solve these issues. But there are limits here as well. AppLink-aware Apps can detect each other, so they can call each other to open URLs. But for calling other Apps which are not AppLink-aware, nothing has changed. So the goal should be that as many (internet-aware) Apps as possible do support AppLink to get the best user experience.</p>
<p>The current implementation of AppLink assumes that a Web Browser (like iCab Mobile), an RSS reader and a Mail App are the most important Apps for accessing the internet, the center of your internet activities. Technically this is because the standard URL schemes of the internet are &#8220;http&#8221;/&#8221;https&#8221; (Web Browser), &#8220;feed&#8221;/&#8221;feeds&#8221; (RSS reader) and &#8220;mailto&#8221; (Mail App) and these are all already supported by the iPhone OS and its default Apps (Safari and Mail).</p>
<p>An example:</p>
<p>There&#8217;s an AppLink-aware Web Browser (like iCab Mobile) and an AppLink-aware Facebook App installed on the iPhone. The Facebook App can open links in an external browser and the user can decide if this browser is iCab Mobile or Safari or maybe another browser. And if the user is currently surfing in the web using iCab Mobile and opens a link to a new interesting facebook profile, iCab Mobile would automatically show or enable a special button. If the user taps on this button, the native facebook app is called with the current facebook URL, so the user can directly add and manage the new facebook profile within the facebook app where he also manages all the other facebook profiles and contacts. The user doesn&#8217;t have to quit and lauch apps manually, the user doesn&#8217;t need to copy and paste URLs etc. All this can be done by AppLink automatically.</p>
<p>Wikipedia Apps, Twitter Apps and many other Apps can be called the same way if they support AppLink. The AppLink-aware browser will know that a Wikipedia App is interested in wikipedia.org URLs and the a Twitter app is interested in &#8220;twitter.com&#8221; URLs, so it can automatically offer to open such URLs in these native Apps.</p>
<p>But also very simple tasks like opening the FAQ page of an App in a web browser or sending an email to the developer of an App  can be done using AppLink (many Apps in the AppStore do have something like this build in, though only calling Safari or Mail). The AppLink solution will call the AppLink-aware browser or AppLink-aware Mail App if available. If these are not available on the device, the default Apps (Safari and Apple Mail) are called. And calling the AppLink-aware App instead of the default one is most likely what the user wants, otherwise he wouldn&#8217;t have installed the alternate apps.</p>
<p>The curent beta version of  &#8221;<strong>iCab Mobile</strong>&#8221; does already support AppLink with all its features. Though there are currently no other AppLink-aware Apps available, the AppLink features can be already used with some of the build-in apps like the native <strong>YouTube</strong> app. When opening a YouTube video page a new button will appear next to the URL field. Pressing this button will offer to open the video in the native YouTube app. And what can be done for YouTube URLs would also work for other URLs (like Facebook, Twitter, Wikipedia etc.). Here&#8217;re some screenshots, how this can look like:</p>
<div>
<p><img src="http://www.icab.de/dev/feed.jpg" alt="" /><br />
At the top you&#8217;ll see the normal URL bar of iCab Mobile, without the special button to the right of the URL field.<br />
To the left you&#8217;ll see an RSS feed that is displayed in iCab Mobile. To the right of the URL bar there&#8217;s a new button. If you tap on this button, iCab Mobile will ask if you want to open the RSS feed in either Safari or in the &#8220;URLTest (RSS)&#8221; App (see the picture to the right). In this example there are two Apps installed, which can open the feed URL and the user can choose in which App to open the RSS feed.</div>
<div>
<p><img src="http://www.icab.de/dev/youtube.jpg" alt="" /><br />
To the left you&#8217;ll see a video page at youtube.com. iCab Mobile knows that the native YouTube app can open the video, so it adds the special button to the right of the URL field again. Tap the button and iCab will ask if you want to open the video in the &#8220;YouTube&#8221; app.</div>
<p>You can download the AppLink class here: <a href="http://www.icab.de/dev/AppLink.zip">AppLink.zip</a> (32 KB)</p>
<p>There&#8217;s also a small web site about AppLink: <a href="http://www.icab.de/dev/AppLink.html">http://www.icab.de/dev/AppLink.html</a></p>
<p>Please spread the word about this AppLink proposal. Hopefully many iPhone App developers will find this useful and will support AppLink in their Apps.</p>
<p>I&#8217;m also looking for feedback, suggestions and critics. So please tell me if you like the idea, if you have suggestions, if you need help etc. Please use the email address &#8220;alexander@icab.de&#8221; or write a comment here. Developers who want to add AppLink support in their Apps and need a counterpart App to test with (like for example iCab Mobile), please contact me as well. Maybe I can provide you with a beta version of iCab Mobile (but there&#8217;re limits in the number of beta versions I can give away).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icab.de/blog/2009/09/12/applink-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Calling iCab Mobile from within Safari on the iPhone</title>
		<link>http://www.icab.de/blog/2009/09/07/calling-icab-mobile-from-within-safari-on-the-iphone/</link>
		<comments>http://www.icab.de/blog/2009/09/07/calling-icab-mobile-from-within-safari-on-the-iphone/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 21:03:20 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[iCab]]></category>
		<category><![CDATA[iPhone & iPod Touch]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[iCab Mobile]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://www.icab.de/blog/?p=53</guid>
		<description><![CDATA[Almost all apps on the iPhone can easily open a URL in Safari. But normally you can&#8217;t open a URL from within Safari in other apps, for example in iCab Mobile (V 1.7). But with a &#8220;bookmarklet&#8221; (a special bookmark which is based on JavaScript code) you can do this as well. Here&#8217;s how the [...]]]></description>
			<content:encoded><![CDATA[<p>Almost all apps on the iPhone can easily open a URL in Safari. But normally you can&#8217;t open a URL from within Safari in other apps, for example in iCab Mobile (V 1.7).</p>
<p>But with a &#8220;bookmarklet&#8221; (a special bookmark which is based on JavaScript code) you can do this as well. Here&#8217;s how the bookmark URL for the bookmarklet should look like:</p>
<pre style="padding-left:0.7em; border-left: 1px solid #030; color: #003300; font-size:0.9em">    javascript:location.href='web'+location.href.substring(4);</pre>
<p>Because you can&#8217;t create Bookmarks from scratch in Safari on the iPhone, you should just create a bookmark of a random page and change its URL to the above line and the title to &#8220;Open in iCab Mobile&#8221;.</p>
<p>If you open this bookmarklet from within the Safari bookmarks, the currently displayed web page is passed to iCab Mobile and opened there.</p>
<p>The bookmarklet simply changes the URL scheme from &#8220;http&#8221; to &#8220;web&#8221; and from &#8220;https&#8221; to &#8220;webs&#8221;. And because iCab Mobile supports the &#8220;web&#8221; and &#8220;webs&#8221; schemes as a replacement for &#8220;http&#8221; and &#8220;https&#8221;, the iPhone OS will pass these modified URLs to iCab Mobile.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icab.de/blog/2009/09/07/calling-icab-mobile-from-within-safari-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>iCab running on WebKit nightly</title>
		<link>http://www.icab.de/blog/2009/07/26/icab-running-on-webkit-nightly/</link>
		<comments>http://www.icab.de/blog/2009/07/26/icab-running-on-webkit-nightly/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 22:37:23 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[iCab]]></category>
		<category><![CDATA[WebKit]]></category>

		<guid isPermaLink="false">http://www.icab.de/blog/?p=9</guid>
		<description><![CDATA[Some iCab users asked me, if iCab 4 can use the latest WebKit nightly builds instead of the built-in WebKit component of Mac OS X. This is indeed possible, and thanks to an Automator Script by David Hall, this is also very easy to do. All you need are the following three files&#8230; a copy of iCab [...]]]></description>
			<content:encoded><![CDATA[<p>Some iCab users asked me, if iCab 4 can use the latest WebKit nightly builds instead of the built-in WebKit component of Mac OS X. This is indeed possible, and thanks to an Automator Script by <a href="http://spotthehall.com/" target="_blank">David Hall</a>, this is also very easy to do. All you need are the following three files&#8230;</p>
<ul>
<li>a copy of <a href="http://www.icab.de/dl.php" target="_blank"><strong>iCab 4</strong></a></li>
<li>the <a href="http://davidhall.me/running-on-webkit.html" target="_blank"><strong>Automator Script</strong></a> from David Hall</li>
<li>a binary copy of the <a href="http://webkit.org/" target="_blank"><strong>WebKit nightly</strong></a> builds</li>
</ul>
<p>Now copy the <strong>iCab 4</strong> application, the <strong>WebKit</strong> application and the Automator Script <strong>iCabWK</strong> into the Applications folder of your Mac. Make sure that neither <strong>iCab</strong> nor <strong>WebKit</strong> are running and double-click the Automator Script <strong>iCabWK</strong>. This will launch iCab so that it will use the WebKit framework that is located within the WebKit application.</p>
<p>To check if iCab is really using the WebKit nigthly build, you can download the <strong><a href="http://trac.webkit.org/wiki/DetectingWebKit" target="_blank">WebKitDetect</a></strong><a href="http://trac.webkit.org/wiki/DetectingWebKit" target="_blank"> script from the WebKit nightly web page</a> and open it in iCab. It will tell you which version of WebKit is currently used. But please make sure that you&#8217;ve configured the <strong>Identity</strong> setting of iCab (in the &#8220;View&#8221; menu) to the default value &#8220;<strong>Best compatibility</strong>&#8220;. The latter is important because changing the identity setting will change the value of the browsers &#8220;UserAgent&#8221; information, and the WebKit detection script is using the UserAgent information to determine the WebKit version that is used.</p>
<p>If you want to use the WebKit nightly within iCab, please always start iCab by double-clicking the iCabWK Automator Script. If you double-click iCab directly, or launch it indirectly by opening a HTML file or an URL, iCab will use the WebKit that is built-in into the system.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icab.de/blog/2009/07/26/icab-running-on-webkit-nightly/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

