By Werner Ruotsalainen on Thu, 11/17/2011
Some of my recent tips you, assuming you're interested in programming mobile devices, may be interested in.
HERE, I've answered a question on whether it's possible to run Ruby (a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features) scripts under iOS. It is.
Unfortunately, you'll need to jailbreak your phone / tablet, should you want to do this. In Cydia, just search for “Ruby”. Install the package and, after that Ruby becomes available from both MobileTerminal (ruby <scriptname> or directly) and your native iOS apps. For the latter, just use the system() call (more on it HERE) just like in the following: “system("ruby scriptpath");”
BTW, if you plan to run Ruby (or anything) from MobileTerminal, make sure you check out THIS for my article on acquiring the current version of MobileTerminal. Unfortunately, the default repositories in Cydia still only have the old (and non-working) version of the app.
Copying the highlighted text in UIWebView to the iOS clipboard
If you know what AppleScript is (it's certainly worth learning as there are a lot of ways it can make your OS X life significantly easier and work faster!), you may also have run into the excellent script HERE). Basically, the script allows you to select some text in a web page, then invoke the script on the selection (preferably via Automator and a hotkey to make the process as quick as possible). If you also incorporate the invocation of BBEdit, a great third-party OS X editor (as is done in the lowermost post by bluedogranch on Feb 18, '08 10:33:41AM), in addition to the selection, also the page URL and the current date will be copied to a new BBEdit document. Then, you will be able to easily save the selection.
This got me thinking. On my iPads, I often collect information from the Web. Up until now, I've done this the following way: first, I copied the section I wanted to save to the clipboard, switched tasks to Notes, pasted the clipboard contents to a new page. Then, switched back to the browser and did the same with the URL so that I don't have to search for the given page again. This all means four task switches and a lot of manual work.
If you frequently save stuff this way, the work involved can become really annoying. No wonder I embarked on discovering how the above-linked AppleScript script can be re-implemented on iOS.
Unfortunately, without jailbreaking, it seems all this impossible.
BTW, with jailbreaking, all this might be possible. I (currently) don't know how it needs to be done on the system level (I'll try to look into the problem) and there's no direct Cydia application for this. The closest equivalent I could find was Action Menu Plus Pack (dedicated article HERE), which has, among other things, a clipboard history list. This may mean reducing the number of required task switches (two instead of four): you copy the selected Web page content and the URL to the clipboard without switching to Notes in between. Only after doing this should you switch to Notes (one task switch) and copy the two items from the clipboard (directly from there and, then, the last-but-one item from the history). However, it still requires work.
I've even created a demo application doing exactly this. The source code can be downloaded HERE. It has a very simple GUI consisting of two buttons (Go / Copy), a textfield to enter the URL and, of course, a UIWebView. The latter two have outlets (only); the former two event handlers (only). The Go button's event handler (in URLAndSelectionCopyDemoViewController.m) is as follows:
NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:[tf text]]];
where tf is the outlet of the text field and web is that of UIWebView. As you can see, the code simply loads the Web page whose address is in the text field.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
s = [s stringByAppendingString:@" :\r----\r"];
pasteboard.string = s;
Finally, here's the GUI:
I'll ask the developer of iCab Mobile, probably the best third-party Web browser, whether he wants to implement this in his browser.
I've posted a quick note on where you can get more information on “graded”, customized UIButtons HERE. Let me cite myself:
Probably the best online custom button tutorial I've run into is at http://ios-blog.co.uk/iphone-development-tutorials/how-to-code-custom-ios-buttons/. It explains how image stretching works, what the “caps” parameters are pretty well and in plain English. (Offline, among other things, I recommend the “Spiffing Up the Button” section (pg. 92) of Beginning iPhone 3 Development by Dave Mark and Jeff LaMarche – if you have the book, of course.) I haven't found the other online tutorials verbose enough – generally, they only present some code, but no image stretching explanation. Before running into the tutorial I've linked to, it took me quite a bit of experimenting to find out how images should be presented.
Some additional example code explaining the four different button states are at, among others, Set a button background image iPhone programmatically.
Stanford University iOS course
While the first series (Winter 2010) of Stanford University's iOS programming course wasn't particularly anything to write home about, the second one (Fall 2010), already led by Paul Hegarty, has already been a very good one. Now, the current, third one, updated to cover iOS5, has started to appear at iTunes University. Highly recommended! I plan to comment on the series in my future articles, explaining what, as an iOS lecturer myself, I would have elaborated on further or would have stated differently.
Windows Phone 7 programming: No second edition of Petzold's classic
I've asked Charles Petzold, the author of, among other things, the free ebook Programming Windows Phone 7 for the publishing date of the second edition of the book, incorporating the (huge) changes in the WP7 programming model (for example, the ability to unite XNA and SilverLight development, which is REALLY a good thing – a decent, dedicated article is HERE) and API's. Unfortunately, it seems there won't be.