Simply genius
Archive for the ‘Computers & Internet’ category
Apple Store Love Song
September 29th, 2009The iTunes App Store review process
August 25th, 2009Being a small fry iPhone app developer, that being I do so in my own spare time because I like developing apps for the iPhone, I’ve simply got to comment about the App Store review process as it stands.
I won’t make any individual comments about my personal rejections I’ve had except to say. I have had a number of rejections.
One update got rejected numerous times because apparently if you use a UIWebView where the user might be able to get to Google and therefore access pictures of <shock>naked people</shock> then you have to rate your App as 17+. Let us ignore the fact that they could just close your app and go to mobile Safari shall we, it would be by far easier?
Another one I reason I’ve been rejected for features not doing something Apple think they should, yet that very same feature was actually in the version before it…. still on sale in the App Store. Inconsistent reviewing doesn’t even begin to cover it!
So this leads me on to a blog post I read today from Joe Hewitt. For anyone who doesn’t know who Joe is, he is the guy who wrote the amazing Facebook app for the iPhone.
I have only one major complaint with the App Store, and I can state it quite simply: the review process needs to be eliminated completely.
Does that sound scary to you, imagining a world in which any developer can just publish an app to your little touch screen computer without Apple’s saintly reviewers scrubbing it of all evil first? Well, it shouldn’t, because there is this thing called the World Wide Web which already works that way, and it has served millions and millions of people quite well for a long time now.
Go and read his excellent post now at what I totally agree with…. especially as I have one app that I originally submitted a month ago, awaiting approval!
Just quit your moaning Opera
July 28th, 2009So I’ve been following the developments of Opera vs Microsoft vs the EU browser war and as far as I understand it this is what’s happened so far
1) The EU has been concerned for sometime that Microsoft has bundled Internet Explorer and wants it removed as a default installation
2) Opera has complained to the EU as well
3) Microsoft has developed a special version of Windows 7 just for the EU which doesn’t have Internet Explorer installed
Now could someone just explain to me for a minute, if the web browser is not installed by default, how the hell are you supposed to get a web browser running without installing IE from the Windows Disk. I don’t know about you but I don’t tend to keep a resource of Web browser installers lying around.
Next comes that, did anyone bother to ask users what they wanted? I didn’t get asked and I don’t really mind IE being installed… I’m not forced to use it and I don’t have to use it if I don’t want to. It’s not like Microsoft prevent you from installing other browsers.
Now I read this morning over at The Register that Microsoft have proposed a browser ballot screen when you install Windows asking you to pick which browser you want installed. Apparently this is the mock up they provided.

To be honest, that screen seems perfectly fine to me, it’s clean, it’s relatively straight forward and offers the most popular browsers around. Now of course you can’t realisically expect Microsoft to put every web browser in existence on the screen either, there are far too many, so who decides who makes the grade?
However I read in that same article that Opera are not happy with that either
Lie has reportly said that the use of icons in the ballot screen could result in a natural bias towards IE. The sticking point could be that the IE logo has become synonymous with Windows.
“The blue ‘e’ has become so associated with the Internet in general, due to the bundling with Windows. We think using the blue ‘e’ might not be such a good idea,” told TechFlash.
My only response is ‘Opera just stop moaning’. Just because your browser is rubbish and no one wants to use it doesn’t mean that you have to go out of your way to make things harder for users. Heck, the Google logo there is highly recognisable so I’d imagine quite a number of users will actually click on that instead of IE.
I’m sure Opera won’t be happy until the screen says do you want to install Opera or if you want to install another click on the little button, type in the URL to a .exe for some other browser… oh and IE is now renamed to ‘FE£RG245wvf”%s TGE£%”V’
Indeed which Opera might have a higher Acid 3 rating than Internet Explorer I’d still rate IE8 above Opera in terms of a better product. If I’d move the logos around in my personal preference I’d only move Internet Explorer and slot it in nicely between Google Chrome and Opera.
However when the next version of Windows comes out I don’t want to buy a cripled version from the EU, I’ll try to find a legal way of getting the US version thank you very much… much like the unused N versions without media player.
UIActionSheet’s cancel button presses not detected properly
July 22nd, 2009Last night I came across a really annoying bug with UIActionSheet when used in conjunction with a UITabBarController.
Basically there is a killer bug which means you can’t click the Cancel button on a UIActionSheet and forces the user to either close the App or use one of the destructive action buttons to get rid of the alert.
It appears to be a changed from OS <= 2.1 to >= 2.2. In iPhone OS 2.1 and earlier, the UIActionSheet comes up from the top of the tab bar, but in 2.2, it comes up from the bottom of the tab bar, and thus covers the tab view but the tab view still takes focus. If you try to press the cancel button below the top of the tab bar (barely visible through the semi-transparent UIActionSheet), the press does not register. If you click above the underlying tab bar, the press does work.
This is how you fix it.
1) In your AppDelegate.h function
+ (UITabBarController *)tabbarController;
Note that tabbarController should be different than your ACTUAL UITabBarController name.
Next edit your AppDelegate.m functiuon and above your @implementation
static AppDelegate *s_appdelegate = nil; @implementation AppDelegate
Inside applicationDidFinishLaunching add
s_appdelegate = self;
At the bottom of AppDelegate.m before @end add
+ (UITabBarController *)tabbarController
{
return s_appdelegate ? s_appdelegate.tabBarController : nil;
}
Finally in your child view in which you wish to display your UIActionSheet add
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Delete?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Yes" otherButtonTitles:nil, nil]; UIView *viewBase = self.view; viewBase = [[AppDelegate tabbarController] view]; [sheet showInView:viewBase]; [sheet release];
iPhone push problems on unlocked phones
July 22nd, 2009I read an article today about Push Notifications being displayed on the wrong people’s phones.
Now if the story is taken at face value then this would be a huge security flaw with the Apple Push Notification Service. However if you dig a little further you discover that it isn’t Apple’s problem at all, more the work of the unlocking community.
Now I’ll first start by explaining how the push notification service works. When you first load an application with push notification enabled, the application makes a call to the APNS (Apple Push Notification Service) servers. Those servers respond with a unique key for that device for push services. That unique key allows Apple to identify which device and which application to target for a push notification.
The App then communicates with the application’s author’s web servers and stores the key somewhere. The author’s servers then use that key to push a JSON encoded payload the APNS servers and the notification gets displayed on the user’s phone.
With me so far? So how does this break on unlocked iPhones?
Well unlocked / hacktivated phones haven’t actually been activated with Apple’s activations servers, they’ve simply been fooled into thinking that they have.
From what I’ve read about this situation is that the hacktivating / unlocking community have taken the key(s) from a properly activated device and put as part of the process.
So what is actually happening is that multiple phones are recieving legitimate push messages for the original key holder but not for them.
At present it would seem that push notifications simply won’t work on hacktivated / unlocked phones.
I guess the lesson is, if the software is written to prevent you from unlocking / by passing activation and then you do bypass it, then don’t expect everything to work properly!
Thank you YouTube for helping kill off IE6
July 15th, 2009Think of the developers…. that and the many man hours wasted trying to get websites to work on an archaic web browser that is Internet Explorer 6.
When it was released IE6 was a good web browser but Internet Explorer 7 was released in October 2006, yes that’s right almost 3 years ago and Internet Explorer 8 has been out for many months now too!
There is simply no excuse for not upgrading, if you have an internal intranet application that requires IE6, dare I say start looking for a new bit of software that has been updated in the past 3 years?
However I noticed over at Techcrunch today “YouTube Will Be Next To Kiss IE6 Support Goodbye” this image taken by a user of Internet Explorer 6:

It just needs a few more major sites to totally drop support for IE6 and the job is done, and it couldn’t come soon enough!
How code push notifications on the iPhone 3.0
July 15th, 2009I recently spent an entire evening trying to get this to work within an App and then post the message from my PHP application to Apple’s service.
First up you must create a CSR using your private key, you must have done this before to even be using the SDK so I’ll skip over it.
Login to the Apple Dev Center then to the iPhone Developer Program Portal.
Click on App IDs and add a New App ID.
- You need to create an App ID without wildcard in the Program Portal (that means one cert for one app. They explain how to do this in the portal)
- Generate a certificate signing request from your Mac’s keychain and save to disk
- Upload the CertificateSigningRequest.certSigningRequest to the Program Portal
- Wait for the generation of cert (about 1 min). Download the certificate (aps_developer_identity.cer) from the Program Portal (and also the distribution certificate if you wish too, we’ll deal with just the developer identity for this)
- Keep the 2 files (steps 2 and 4) in a safe place. You might need the CertificateSigningRequest.certSigningRequest file to request a production cert in the future or renew it again.
- Import the aps_developer_identity.cer to the keychain. Then you have to export these new cert and the private key of this cert (not the public key) and saved as .p12 files.
- Then you use these commands to generate the cert and key in Mac’s Terminal for PEM format (Privacy Enhanced Mail Security Certificate)
openssl pkcs12 -clcerts -nokeys -out certificate.pem -in cert.p12 openssl pkcs12 -nocerts -out key.pem -in key.p12
- The certificate and private key files are used by your software to communicate with APNS
- You might want to remove the passphrase from the private key (you don’t have to do this but it makes it slightly more complicated in your code). To do this
openssl rsa -in key.pem -out key.unencrypted.pem
Then you’ll need to generate a single .pem file combining your certificate and key files
cat certificate.pem key.unencrypted.pem > apnsdev.pem
So copy the generate apnsdev.pem file to your server and then you can setup your PHP application to push notifications to your iPhone.
$deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // masked for security reason
// Passphrase for your private key
// $pass = '';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apnsdev.pem');
// assume the private key passphase was removed.
// stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstr\n";
}
else {
print "Connection OK\n";
$payload = '{"aps":{"badge":' . $number . '}}';
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);
}
Note: if as a developer you install your app with your developer provision profile you’ll have to use the sandbox to communicate with your phone, you won’t be able to use the production push servers without the distribution profile
So that’s stage one, how to configure your web server with PHP to push to an iPhone, but how does the App actually register itself for push and secondly how do you get the device token to your server?
In XCode, in AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// This tells APNS that you wish to receive both Badge notifications and sound
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
Then we can make two delegate functions in AppDelegate.m too
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken: %@", deviceToken);
[self sendToMyServer:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Error in registration. Error: %@", error);
}
You’ll need to create a function for ’sendToMyServer’ and deal with the deviceToken, such as convert it to a string, etc. But essentially that is how you deal with push notifications on your iPhone!
Update: Oh and if you get the error
Warning: stream_socket_client() [function.stream-socket-client]: Unable to set local cert chain file `apnsdev.pem'; Check that your cafile/capath settings include details of your certificate and its issuer in /Library/WebServer/Documents/notifyTest/anps.php on line 33
or similar, the chances are you’ve exported the wrong certificate and/or key from your OS X Keychain
adLDAP 3.2
June 26th, 2009Over the past few weeks I’ve been hacking to bits adLDAP to suit my own needs. Of course I’ve contributed those findings back to the community in the adLDAP library at http://adldap.sourceforge.net
Version 3.2 of adLDAP has a lot more under the skin than would first imply by the version number. Firstly in version 3.0 I made adLDAP truly PHP 5.x only with protected configuration variables. However in adLDAP 3.2 I’ve allowed overloading with getters and setters that I’ve previously blogged on.
I’ve also added new computer information functions, I’ve also created a connect and disconnect function. The intention is to allow changing connection details mid script. The constructor and destructor normally handle the connections and disconnections but there might be a need to change certain connection properties mid-script and that is the point of these new functions.
I’ve also added a new folder_list() function. This function will deliver a list of objects, whether they be OU’s, users, groups, etc in a specific OU. With this function I believe you could effectively deliver a web based Active Directory User’s and Computers application.
See http://adldap.sourceforge.net/wiki/doku.php?id=api for more information.
Getters and Setters in PHP?
May 30th, 2009This is the question I’ve been pondering this week.
In older versions of PHP other than to keep code neat there was no real need for this functionality, but with PHP 5 you can declare access properties for variables and functions in classes. In other OO languages, such as C# we’ve been used to it for a long time. In traditional OOP, if we wanted to get or set an object’s private member, we would need to write a public method to do the job.
The reason behind making a member data private and then accessing it through a public method is to avoid the implementing-user to access it directly. There can be many reasons for prohibiting direct access to member data to the implementing-code.
PHP traditionally has a weak type system, a further check of the data type may be necessary. PHP 5 and C# .NET have a getter and setter method feature, making it look like we’re accessing the data member directly.
For instance in PHP
class Circle
{
private $radius; # integer
# Constructor
public function __construct($radius = 15)
{
self::__set('radius', $radius);
}
# Setter
public function __set($name, $value)
{
switch ($name)
{
case 'radius':
if (!is_numeric($value)) # is_int() for strict type checking
throw new Exception('Radius must be of a numeric type');
if ($value < 10 || $value > 500)
throw new Exception('Radius must be within the range of 10 - 500');
$this->radius = $value;
break;
default:
throw new Exception("Attempt to set a non-existing property: $name");
break;
}
}
# Getter
public function __get($name)
{
if (in_array($name, array('radius')))
return $this->$name;
switch ($name)
{
default:
throw new Exception("Attempt to get a non-existing property: $name");
break;
}
}
}
$c = new Circle();
$c->radius = 25;
echo $c->radius;
The problems with this method are two fold. Firstly, because PHP is a weakly typed language you can’t really guarantee that the set and get are in the right format so you have to handle that in the __set and __get functions, and secondly you would be able to set or get any private variable in that class.
Based on the second point, is it therefore worth actually defining a manual setter and getter for each private variable you want to allow access to? For example:
class test {
private $count;
public function setCount( $value )
{
$this->count = $value;
}
public function getCount()
{
return $this->count;
}
}
Because if we use this method we could actually check in the setter if the variable is_int($value) and throw an exception if it isn’t.
My question is, based on the fact that traditionally PHP is a weakly typed language, is it worth
- using the traditional OO format of getters and setters __get and __set
- is it worth declaring your own get and set public functions for only specific variables you want to allow
- or is it worth just making the variable public and setting it directly from outside the class e.g.
class testClass {
public $count;
}
$myclass = new testClass();
$myclass->count = 1;
The reason I ask is that is that I’m considering how to handle getters and setters in adLDAP. adLDAP is a PHP library that I’m one of two developers maintaining. This is an open source library that provides Microsoft Active Directory integration over LDAP for PHP scripts, such as creating user accounts, Exchange mailboxes, managing groups and authentication, etc.
The library currently has private member variables for things such as the domain controller, a domain admin username and password, ssl settings, etc. The __construct function also allows these to be set through an array passed to it. However I have the need to actually disconnect from my domain controller, change a property and re-connect again. So my reason for this post is, what’s the best way to handle these getters and setters based on my three choices above?

