Archive for the ‘Uncategorized’ Category

Setting up IIS 6 for HTTPS

Sunday, September 5th, 2010

In order to set IIS 6 to respond HTTPS requests the server must be configured with Certificate.
The certificate can be requested from Certificate Authorities, or you can simply self certificate the server.
For the second option you need to follow these simple steps:
1) Download and Install IIS 6.0 Resource Kit Tools from:

http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&displaylang=en

2) Once IIS Resource Kit installed, open IIS Metabase Explorer (Start menu->Programs->IIS Resources->Metabase Explorer). Go to LM->W3SVC and select the items on the left to see on the right a description of them and find your virtual site (the default Web Site usually has ID 1). At this point, suppose the site has ID=123 you have to issue run from command prompt (you might need to change current directory to ‘Program Files\IIS Resources\SelfSSL’):

SelfSSL /N:CN=yoursite.yourdomain.com /V:365 /S:123

where:

/N:CN is the name of your site on the internet (or LAN)
/V: sets the number of days before the new certify expires
/S: is the ID we found

After this command line is completed, the site is ready to go.

Adding Local Weather Conditions To Your App (Part 1/2: Implementing CoreLocation)

Friday, September 3rd, 2010


Knowing the latitude and longitude of your users can open up all kinds of possibilities in your apps. In an upcoming post, we’ll be discussing how you can use your user’s location to determine their local weather conditions and forecast. But for now, we’re going to focus on Part 1 of this two part tutorial: CoreLocation.

Apple’s done a great job of abstracting GPS, Cellular Triangulation, and Wifi Access Point location lookups into CoreLocation; making it extremely easy to determine the approximate location of your user regardless of their device and network connectivity. Additionally, Apple’s new iPhone Simulator finally supports CoreLocation as well. This significantly eases the process of testing your location code.

The first thing you’ll need to do is add the CoreLocation framework to your project. This is pretty straightforward. Command-Click on ‘Frameworks’ -> Add -> Existing Frameworks

Select ‘CoreLocation.framework’ and click ‘add’.

The class below implements the LocationManager delegate methods required to get the user’s location. You can just as easily implement the LocationManagerDelegate protocol in your AppDelegate or elsewhere in your App. Though I’ve found that having this class makes it super easy to drop in location support into new projects instead of having to cut/paste delegate methods (ugly). Anyway. Take a look:

//
//  LocationGetter.h
//  CoreLocationExample
//
//  Created by Matt on 9/3/10.
//  Copyright 2009 iCodeBlog. All rights reserved.
//
 
#import 
#import 
 
@protocol LocationGetterDelegate 
@required
- (void) newPhysicalLocation:(CLLocation *)location;
@end
 
@interface LocationGetter : NSObject  {
    CLLocationManager *locationManager;
    id delegate;
}
 
- (void)startUpdates;
 
@property (nonatomic, retain) CLLocationManager *locationManager;
@property(nonatomic , retain) id delegate;
@end

Notice that we’re defining our own protocol with a method that takes the new CLLocation as a parameter. We’ll be implementing that delegate method in a minute. Now for the class

//  LocationGetter.m
//  CoreLocationExample
//
//  Created by Matt on 9/3/10.
//  Copyright 2009 iCodeBlog. All rights reserved.
//
 
#import "LocationGetter.h"
#import 
 
@implementation LocationGetter
 
@synthesize locationManager, delegate;
BOOL didUpdate = NO;
 
- (void)startUpdates
{
    NSLog(@"Starting Location Updates");
 
    if (locationManager == nil)
        locationManager = [[CLLocationManager alloc] init];
 
    locationManager.delegate = self;
 
    // locationManager.distanceFilter = 1000;  // update is triggered after device travels this far (meters)
 
    // Alternatively you can use kCLLocationAccuracyHundredMeters or kCLLocationAccuracyHundredMeters, though higher accuracy takes longer to resolve
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    [locationManager startUpdatingLocation];
}
 
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your location could not be determined." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];
}
 
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (didUpdate)
        return;
 
    didUpdate = YES;
    // Disable future updates to save power.
    [locationManager stopUpdatingLocation];
 
    // let our delegate know we're done
    [delegate newPhysicalLocation:newLocation];
}
 
- (void)dealloc
{
    [locationManager release];
 
    [super dealloc];
}
 
@end

CoreLocation gives you a few options for the accuracy of the user’s location. The more accurate the measurement, typically the longer it takes LocationManager to call it’s delegate method didUpdateToLocation. It’s just something to keep in mind when deciding what level of accuracy to use.

Next we need to actually invoke this code and start getting location updates. I usually do this in my AppDelegate’s didFinishLaunchingWithOptions, though you could also do it in viewDidLoad somewhere if you didn’t need to know the user’s location on app startup.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
 
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
	spinner.center = CGPointMake(self.viewController.view.frame.size.width / 2, self.viewController.view.frame.size.height / 2);
    [spinner startAnimating];
 
    [viewController.view addSubview:spinner];
 
    // get our physical location
    LocationGetter *locationGetter = [[LocationGetter alloc] init];
    locationGetter.delegate = self;
    [locationGetter startUpdates]; 	
 
    // Add the view controller's view to the window and display.
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
 
    return YES;
}

Notice that I’ve set locationGetter’s delegate to self. So in your .h, make sure to add LocationGetterDelegate to the interface.

//
//  CoreLocationExampleAppDelegate.h
//  CoreLocationExample
//
//  Created by Matt Tuzzolo on 9/3/10.
//  Copyright iCodeBlog 2010. All rights reserved.
//
 
#import 
#import "LocationGetter.h"
 
@class CoreLocationExampleViewController;
 
@interface CoreLocationExampleAppDelegate : NSObject  {
    UIWindow *window;
    CoreLocationExampleViewController *viewController;
    CLLocation *lastKnownLocation;
}
 
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet CoreLocationExampleViewController *viewController;
@property (nonatomic, retain) CLLocation *lastKnownLocation;
 
@end

I’ve also added a CLLocation *lastKnownLocation that we’ll use in our delegate method (which comes next):

# pragma mark -
# pragma mark LocationGetter Delegate Methods
 
- (void)newPhysicalLocation:(CLLocation *)location {
 
    // Store for later use
    self.lastKnownLocation = location;
 
    // Remove spinner from view
    for (UIView *v in [self.viewController.view subviews])
    {
        if ([v class] == [UIActivityIndicatorView class])
        {
            [v removeFromSuperview];
            break;
        }
    }
 
    // Alert user
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Found" message:[NSString stringWithFormat:@"Found physical location.  %f %f", self.lastKnownLocation.coordinate.latitude, self.lastKnownLocation.coordinate.longitude] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];  
 
    // ... continue with initialization of your app
}

This last piece takes care of storing the location, removing the spinner, and firing off an alert. If this was your code, you’d probably want to re-enable any UI elements that you’ve disabled and let the user start using your app.

For those of you who don’t know me yet, my name is Matt Tuzzolo (@matt_tuzzolo). This is my first iCodeBlog post; with many more to come.

Here’s the Example Project for this post. Enjoy!

ZumoCast Streams Media to iPad, iPhone From a Home Computer

Tuesday, July 27th, 2010

The ZumoDrive folks are at it again, but this time, they’re taking the cloud storage to your home computer so you can stream media files right to an Apple iPad using ZumoCast. The new ZumoCast service is a take on my “personal cloud” thought — instead of storing data on a third-party web server, ZumoCast shares the files already on your PC or Mac. You just tell ZumoCast which files or folders you want remote access to and the software does the rest. The company is wise to go after the iPad market since the device makes for a great mobile media player.

DRM-protected files won’t play on an iPad or iPhone using ZumoCast, but that’s about the only major limitation aside from requiring your home computer to be powered on. However, you can sync media files with ZumoCast for offline playback on a mobile device — in that case, the home computer can be sleeping peacefully. The ZumoCast desktop software handles all file-sharing aspects and it supports adaptive transcoding. That means the audio and video quality will adjust on the fly to offer the best experience based on your web connection.

Initially for iPad and iPhone, ZumoCast is planned for additional mobile platforms. That makes sense as ZumoDrive, the cloud storage service, is also supported on Google Android and Palm webOS handsets. The company also says that “video sharing and enhanced music and photo interfaces” are in the works. ZumoCast is in an open beta, so you can sign up to try it. At this time, no pricing has been announced for the media streaming service.

Related research on GigaOM Pro (sub req’d):


Alcatel-Lucent NextGen Communications Spotlight — Learn More »

ZumoCast Streams Media to iPad, iPhone From a Home Computer

Tuesday, July 27th, 2010

The ZumoDrive folks are at it again, but this time, they’re taking the cloud storage to your home computer so you can stream media files right to an Apple iPad using ZumoCast. The new ZumoCast service is a take on my “personal cloud” thought — instead of storing data on a third-party web server, ZumoCast shares the files already on your PC or Mac. You just tell ZumoCast which files or folders you want remote access to and the software does the rest. The company is wise to go after the iPad market since the device makes for a great mobile media player.

DRM-protected files won’t play on an iPad or iPhone using ZumoCast, but that’s about the only major limitation aside from requiring your home computer to be powered on. However, you can sync media files with ZumoCast for offline playback on a mobile device — in that case, the home computer can be sleeping peacefully. The ZumoCast desktop software handles all file-sharing aspects and it supports adaptive transcoding. That means the audio and video quality will adjust on the fly to offer the best experience based on your web connection.

Initially for iPad and iPhone, ZumoCast is planned for additional mobile platforms. That makes sense as ZumoDrive, the cloud storage service, is also supported on Google Android and Palm webOS handsets. The company also says that “video sharing and enhanced music and photo interfaces” are in the works. ZumoCast is in an open beta, so you can sign up to try it. At this time, no pricing has been announced for the media streaming service.

Related research on GigaOM Pro (sub req’d):


Alcatel-Lucent NextGen Communications Spotlight — Learn More »

Asset Libraries and Blocks in iOS 4

Thursday, July 8th, 2010


iOS 4 presented a million billion new API’s by Apple’s count, but for this post I am going to show a quick demo of the new Assets Library API where you can now get to users photos and videos with more access than ever before. This new API relies on the new programming device called Blocks that has been introduced with iOS 4. Blocks are used through many of the new API’s as a kind of extended @selector. We will look into this new development device and make a small project to create our own UIImagePickerController. In the end we are going to create a tableview that is filled with all the photos within our library. Check out the video below or follow the steps typed out below.

Screencast

Using the Assets Library API in iOS 4 from Collin Ruffenach on Vimeo.

Creating the Project

Create a new project in xCode. Make it for the iPhone since this is an iOS 4 framework. A view based application will create a view controller for us, so lets use that. Call your project MyImagePicker.

Adding in the framework

This project will revolve around taking advantage of the AssetsLibrary framework introduced with iOS 4. Due to this you must have the newest xCode and iPhone SDK installed with iOS 4.0 support. If this is done you should be able to expand the frameworks folder of your project. Right click on UIKit.framework and select “Reveal in Finder”. This will open up the folder that contains all of the frameworks you can use in an iOS 4 project. Find AssetsLibrary.framework and drag into the Frameworks folder of your project. Once dragged in make sure that the Copy items into destination folder options is deselected and that it is set to recursively create groups for any added folders.

Using the framework with blocks

iOS 4.0 introduces a totally new programming concept for Objective C developers to take advantage of when creating their own code and when using Apple’s API. Blocks in the most simple terms are Objective C objects that are methods. A block uses the special character ^ to denote its beginning and is a required parameter of many of the API’s introduced within iOS 4.0. Apple has some great documentation on blocks, and how they conceptually fit into the current objective C landscape. You can see their concise but effective overview here. For our purposes I am just going to review the simple syntax of a block.

Before we dive into blocks lets take a look at the AssetsLibrary framework methods that will require them. The general flow of the object access we will be doing is as follows.

We are going to create an ALAssetsLibrary and call a method on it that will enumerate through all the ALAssetsGroups it has access to. For every ALAssetsGroup we will call a method on it which will enumerate through the ALAssets it has access to. We will save each ALAsset into an array we will use to populate our tableview. The two different enumerations we are going to perform is where the blocks will come in. But lets first set up our view controller appropriately.

MyImagePickerViewController.h

#import <UIKit/UIKit.h>;
#import <AssetsLibrary/AssetsLibrary.h>;
@interface MyImagePickerViewController : UIViewController {
 
	IBOutlet UITableView *tableview;
	IBOutlet UIActivityIndicatorView *activity;
 
	NSMutableArray *assets;
}
 
@property (nonatomic, retain) IBOutlet UITableView *tableview;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activity;
 
@end

We are going be using the assets array here to hold the assets that we are going to pull using the AssetsLibrary Framework.

Now open up MyImagePickerViewController.xib and drag in a UITableView and a UIActivityIndicatorView. With these in place connect them to the IBOutlets you created for this class. Also make sure to connect the UITableViewDataSource and UITableViewDelegate to the MyImagePickerViewController as well. With that done we can start to use the AssetsLibrary Framework.

Using the Asset Library

Now we are going to use our AssetsLibrary framework. This will be done within the viewDidLoad method of your MyImagePickerViewController.m. Put the following code in there.

1 - (void)viewDidLoad {
2
3    [super viewDidLoad];
4    [activity startAnimating];
5
6    void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
7	if(result != NULL) {
8		NSLog(@"See Asset: %@", result);
9		[assets addObject:result];
10
11	}
12    };
13
14    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
15	if(group != nil) {
16		[group enumerateAssetsUsingBlock:assetEnumerator];
17	}
18
19
20	[self.tableView reloadData];
21	[self.activity stopAnimating];
22	[self.activity setHidden:YES];
23    };
24
25    assets = [[NSMutableArray alloc] init];
26    library = [[ALAssetsLibrary alloc] init];
27    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
28					   usingBlock:assetGroupEnumerator
29					 failureBlock: ^(NSError *error) {
30						 NSLog(@"Failure");
31					 }];
32 }

We are going to be going though this code line by line. On line 4, we start animating our activity indicator. I will explain why we have to do that a little bit later. Lines 6 – 23 are the lines that will  declare the two blocks that we will use to fill our tableview with pictures. We are going to declare two blocks to use as parameters to methods within a ALAssetLibrary object and a ALAssetGroup object. The first method call we will make will be on our ALAssetLibrary object. So for the moment lets skip passed the block declarations and look at line 25. On line 25 we instantiate our NSMutableArray to hold the ALAssets that we will pull out from the AssetsLibrary. On line 26 we will create our ALAssetsLibrary object. We will call a single method on this object to loop through all of the assets in a library. The method is:

– enumerateGroupsWithTypes:usingBlock:failureBlock:

This method takes in 3 parameters. An ALAssetGroup type, a block to be performed on each group and a block to be performed on failure. Lets talk about block syntax. A block is a native Objective C object. It is a subclass of NSObject. With that said it is also an Objective C method. An objective C method is composed of three things. A return type, a parameter list and a piece of code to be executed. We are going to pass the assetsGroupEnumerator block object that declare on line 14 into this method. Lets take a look at how the block is declared.

You begin by specifying a return type for the block. Void in this case. Next you enclose a name for the block which is proceeded by a carrot ^ character. This is the special character Apple has decided on to denote blocks. You begin block names with blocks as well as the actual declaration of what a block is. This name is wrapped in parenthesis. This is followed by the parameter list that the block will accept. In this case it is a ALAssetsGroup object and a Boolean indicating whether to stop. Now I did not come up with these parameters by myself. Since I will be passing this block into an ASAssetLibrary the documentation will tell us what will be passed into the block. ALAssetsLibrary objects documentation can be seen here. With that all said, lets take a look at the code that will actually compose this block. Starting on line 15 we will make sure that we are seeing a valid group. If the ALAssetsGroup object that we are passed is valid then we will call another enumeration on the group which will enumerate through assets. This enumeration method also requires a block. We declared this block above. This block is called assetEnumerator. Once again we retrieved the parameters list from the documentation of the object asking for, in this case an ALAssetsGroup.

For this block, which begins on line 6, the block is passed an ALAsset object, an index and a stopping condition boolean. Within the code of the block we will ensure that the returned ALAsset is valid and if it is we will add it to our array which will hold all of our assets. With this block declared we pass it into the call to our ALAssetsLibrary object on line 16.  Once every group has been enumerated and our array is filled with all of our ALAssets we will tell the tableview to reload its data and get rid of our UIActivityIndicatorView.

With all of this done all that remains if filling in the required UITableViewDataSource methods. The tableview will be filled with the assets we collected. ALAsset objects are cool in that they include a method called -thumbnail which returns a CGImageRef to a thumbnail we will use. I won’t explain the development of these methods any further since they are pretty straight forward.

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
 
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [assets count];
}
 
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
    static NSString *CellIdentifier = @"Cell";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
 
	ALAsset *asset = [assets objectAtIndex:indexPath.row];
	[cell.imageView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
	[cell.textLabel setText:[NSString stringWithFormat:@"Photo %d", indexPath.row+1]];
 
    return cell;
}