Thursday, May 5, 2011

Adding a new user account to Mac

System Prefs Icon

Adding a new user account to your computer

You can create individual user accounts for each person who uses your computer. Each new user has a separate home folder and can adjust his or her own preferences without affecting other users.
  1. Choose Apple menu > System Preferences and click Accounts.
  2. If some settings are dimmed, click the lock icon and type an administrator name and password.
  3. Click Add (+) and type the user’s name.
  4. If you don’t want to use the short name generated automatically, type a new short name. (Once the account is created, you won’t be able to change the short name.)
  5. Type the user’s password in the Password and Verify boxes.
  6. Type a hint to help the user remember the password if they have trouble remembering it at login.
  7. Click Parental Controls and select options to determine what the user can do with the computer.
If you change your mind while you’re creating a new user account, click Delete (-) to cancel.

How To Easily Share Files Between Mac & Windows Computers

File sharing between Macs and Windows is a little lob-sided. Out of the box, Macs can detect any Windows computer connected to the local network. It appears right on the Finder’s sidebar. So naturally, it is very easy for a Windows user to share their files with anyone on a Mac. The reverse process – allowing a Mac to share its files – requires a little more attention. The transition from Tiger to Leopard has made it a little bit more complicated for regular users to set up shared folders because the setting has been “disguised”.
In this week’s Macnifying OS X, I’m going to show you how easy it is to share files on your Mac so that it appears on Windows computers automatically.
how to share files between mac and pc



In System Preferences, go to ‘Sharing’ and check the box for ‘File Sharing’. By default, only your Public Folder will be shared. If you want to add other folders to the shared list, click on the ‘+’ sign under the Shared Folder box and choose the folders you wish to share.
After you’re done selecting, you’ll need to set the Permissions for each shared folder. Generally, you should allow Read Only rights to avoid others from messing around with your files. As you can see from the screenshot below, I removed the group labelled ‘Users’ from the users list so only ‘Everyone’ and I appear on the list. I do this to make things easier, only to allow guests logins from other computers.
share files between computers
Next, click on ‘Options’ and on the resulting window, check the box that says “Share files and folders using SMB” and hit ‘Done’.
share files mac windows
Now, you’ll need to add your Mac into a Microsoft workgroup. To do this, click ‘Show All’ at the top of the System Preferences windows and click on ‘Network’. Select your active connection and click ‘Advanced’.

In the window which pops up, click on the ‘WINS’ tab and enter a workgroup in the appropriate field. Microsoft has two workgroups: MSHOME and WORKGROUP. Find out which workgroup the majority of your Windows computers belong to and set the workgroup to that.
Click on ‘OK’ and you’ll return to Network preferences, now hit ‘Apply’. Now you’re halfway there – the rest of the work is performed on the Windows machines.

On your Windows desktop, right-click on ‘My Computer’ and select Properties. Click on the ‘Computer Name’ tab and make sure that your workgroup is the same as the one set on your Mac. If it isn’t then click on ‘Change’, set it and restart your computer.
Once that is done, double-click on ‘My Network Places’ and voila, all of your Mac’s shared folders should be visible. Take note that the Drop Box in your Mac’s Public folder won’t be accessible. If you want to use the Drop Box to let other users “drop” their files onto your Mac, you’ll need to change its permissions.
On your Mac’s Home folder, double-click the Public folder. Right-click on Drop Box and choose ‘Get Info’. Click on the lock icon on the bottom right hand corner of the Info window and enter your account password. Then set the permission for Everyone to Read & Write hence, allowing anyone to conveniently “drop” files onto your Mac.

Did you find this tutorial easy to follow? Did it work for you? Is there an easier way to share files between Mac and Windows computers?

iphone/ipad force shutdown

iPhone 3G Force Shut-Down


I’ve had my iPhone 3G for a bit over 2 weeks now and am loving it!
But it is a bit glitchy at locking up (especially when the battery is low or you disconnect during a sync with iTunes)
If some does happen (such as the unlock screen not accepting your keystrokes to unlock it and you can’t for some reason power off just by holding the top button for a few seconds) then you either have to drain the battery
- lengthy and not great if as me you may have to do something such as get on a plane!
Or much more handily, use the force power down – like on any computer, iPod etc.
(The image shows a key being pressed, however this digit isn’t being recognised by the phone – this is when you may need to force quit)

What you do is press and hold the top right button (for locking/unlocking) and also the big button at the bottom of the screen – hold them down for between 5 – 10 seconds, and your phone will just switch off
Turn as normal and it should work!

iPhone SDK: Testing Network Reachability

Check Network Resources Before Use

reachability-alert

Using Facebook-connect for iPhone SDK to post stories to Facebook is a great feature to add to your iPhone application. But what happens if the user has no access to the network? If you don’t check the network, the answer is nothing. This leads to user confusion, and it will prevent your app from being approved for the App Store.
So, how do you check? Apple provided a sample application called Reachability which provides the answer. I’ll demonstrate here. In several blog posts people felt that the Reachability sample was overkill for their needs. If you agree, here’s a link to a recipe from The iPhone Developer’s Cookbook that provides an alternate solution. Even if you don’t plan on using it, I recommend reading through the code in the Reachability example.

Project Setup

In an earlier post I used the Facebook-Connect for iPhone SDK to post stories to Facebook. I’ll use the same project to demonstrate how to check that Facebook is reachable. Here’s the project with the API Keys and Template Bundle IDs removed. fbconnect-iphone.zip I’ll include a link to the final project at the end.
Download the Reachability project too. I’ll be importing a class from it to check the network connection status.



Adding the SystemConfiguration Framework

sysconfig
The reachability class uses the SystemConiguration Framework to check network reachability. Adding the framework to the project is easy.
  1. Open Connect.xcodeproj if you haven’t already.
  2. In the Groups & Files area, control click on the Frameworks folder and select Add => Existing Frameworks.
  3. Look in the Frameworks folder for the SystemConfiguration.framework folder and select it.
  4. Click Add to add the framework to your project.

Add the Reachability Class

Now add the Reachability Class from Apple’s sample.
  1. Control click on the Source folder in the project and select Add => Existing Files.
  2. Navigate to the Reachability project, click Classes, and select the files: Reachability.h and Reachability.m.
  3. Click Add, then select Copy items into destination group’s folder (if needed)
  4. Click Add again.

Using the Reachability Class

Now that the framework and class have been added to the project, put them to work in the code. Create a variable to track the internet connection status, and two methods in the SessionViewController.h file.
  1. Open the SessionViewController.h file and import the Reachability class:
    #import "Reachability.h"
  2. Add a variable to track the status:
    NetworkStatus internetConnectionStatus;
  3. Add a property to hold the network status:
    @property NetworkStatus internetConnectionStatus;
  4. Add these two methods:
    - (void)reachabilityChanged:(NSNotification *)note;
    - (void)updateStatus;
At this point, the SessionViewController interface should look like this:
#import "FBConnect/FBConnect.h"
#import "PermissionStatus.h"
#import "Reachability.h"

@class FBSession;

@interface SessionViewController : UIViewController
<FBDialogDelegate, FBSessionDelegate, FBRequestDelegate,
 PermissionStatusDelegate> {
IBOutlet UILabel* _label;
IBOutlet UIButton* _permissionButton;
IBOutlet UIButton* _feedButton;
IBOutlet FBLoginButton* _loginButton;
FBSession* _session;
PermissionStatus *permissionStatusForUser;
NetworkStatus internetConnectionStatus;
}

@property(nonatomic,readonly) UILabel* label;
@property (nonatomic, retain) PermissionStatus *permissionStatusForUser;
@property NetworkStatus internetConnectionStatus;

- (void)askPermission:(id)target;
- (void)publishFeed:(id)target;
- (void)reachabilityChanged:(NSNotification *)note;
- (void)updateStatus;

@end
Finally, the implementation.
  1. Open SessionViewController.m.
  2. Sysnthesize the internetConnectionStatus variable:
    @synthesize internetConnectionStatus;
  3. Define a string for the host name of the resource:
    #define kHostName @"www.facebook.com"
  4. Make the viewDidLoad method look like this:
    - (void)viewDidLoad {
    //Use the Reachability class to determine if the internet can be reached.
    [[Reachability sharedReachability] setHostName:kHostName];
    //Set Reachability class to notifiy app when the network status changes.
    [[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES];
    //Set a method to be called when a notification is sent.
    [[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(reachabilityChanged:) 
    name:@"kNetworkReachabilityChangedNotification" object:nil];
    [self updateStatus];
    [_session resume];
    _loginButton.style = FBLoginButtonStyleWide;
    }
    I want to receive notifications if the network status changes, so I used the setNetworkStatusNotificationsEnabled:YES method. However, I found that the reachabilityChanged method wasn’t called when the network status changed. I’ll refactor later to fix the problem.
  5. Implement the new methods:
    - (void)reachabilityChanged:(NSNotification *)note {
    [self updateStatus];
    }

    - (void)updateStatus
    {
    // Query the SystemConfiguration framework for the state of the 
    device's network connections.
    self.internetConnectionStatus =
     [[Reachability sharedReachability] internetConnectionStatus];
    if (self.internetConnectionStatus == NotReachable) {
    //show an alert to let the user know that they can't connect...
    UIAlertView *alert = [[UIAlertView alloc] 
    initWithTitle:@"Network Status" 
    message:@"Sorry, our network guro determined that the network is not available.
     Please try again later." delegate:self cancelButtonTitle:nil 
    otherButtonTitles:@"OK", nil];
    [alert show];
    } else {
    // If the network is reachable, make sure the login button is enabled.
    _loginButton.enabled = YES;
    }
    }
    To update the user of the status, I display an alert with a message. When status notifications are sent later, either enable the login button or display the alert.
  6. Add the alert delegate method:
    #pragma mark AlertView delegate methods
    - (void)alertView:(UIAlertView *)alertView 
    clickedButtonAtIndex:(NSInteger)buttonIndex {
    _loginButton.enabled = NO;
    [alertView release];
    }
    If the network isn’t available, disable the loginButton. In this app nothing can be done without a connection, so additional information would be in order.
To test the application on the simulator, go to Network Preferences and disable your network connections. While disabled, the alert will be displayed. To test on an iPhone, put the device in Airplane mode. On an iPod, turn off the WiFi connection. I also tested on my device by walking to places where there is no Edge or WiFi network. In my tests, the reachabilityChanged method did not get called. Thanks to Shashi Prabhakar for giving me a clue about how to get it working, see his comment below.

Refactoring to Receive Reachability Changed Notifications

To get the change notifications I had to make several small changes. My initial observations when checking the remoteHostStatus instead of the internetConnectionStatus:
  1. The reachabilityChanged method was being called.
  2. I noticed that when first initialized the remoteHostStatus is always NotReachable.
  3. The internetConnectionStatus returns a positive result before the remoteHostStatus.
  4. Because I am using an alert, sometimes the alert would be displayed twice or not at all when using one status or the other.
As a result, I changed the code to track both the remoteHostStatus and the internetConnectionStatus. I also added a method to initialize the variables.
  1. Open SessionViewController.h and add a variable and property to hold the remoteHostStatus.
    NetworkStatus remoteHostStatus;
  2. Also add a method to initialize the variables.
    - (void)initStatus;
Here’s the complete interface.
#import "FBConnect/FBConnect.h"
#import "PermissionStatus.h"
#import "Reachability.h"

@class FBSession;

@interface SessionViewController : UIViewController
<FBDialogDelegate, FBSessionDelegate, FBRequestDelegate, 
PermissionStatusDelegate> {
IBOutlet UILabel* _label;
IBOutlet UIButton* _permissionButton;
IBOutlet UIButton* _feedButton;
IBOutlet FBLoginButton* _loginButton;
FBSession* _session;
PermissionStatus *permissionStatusForUser;
NetworkStatus internetConnectionStatus;
NetworkStatus remoteHostStatus;
}

@property(nonatomic,readonly) UILabel* label;
@property (nonatomic, retain) PermissionStatus *permissionStatusForUser;
@property NetworkStatus internetConnectionStatus;
@property NetworkStatus remoteHostStatus;

- (void)askPermission:(id)target;
- (void)publishFeed:(id)target;
- (void)reachabilityChanged:(NSNotification *)note;
- (void)updateStatus;
- (void)initStatus;

@end
Edit the implementation.
  1. Open SessionViewController.m and add the initStatus method
    -(void)initStatus {
    self.remoteHostStatus = 
    [[Reachability sharedReachability] remoteHostStatus];
    self.internetConnectionStatus =
     [[Reachability sharedReachability] internetConnectionStatus];
    }
  2. Change the viewDidLoad method to call the initStatus method instead of the updateStatus method.
    - (void)viewDidLoad {
    //Use the Reachability class to determine if the internet can be reached.
    [[Reachability sharedReachability] setHostName:kHostName];
    //Set Reachability class to notifiy app when the network status changes.
    [[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES];
    //Set a method to be called when a notification is sent.
    [[NSNotificationCenter defaultCenter] 
    addObserver:self selector:@selector(reachabilityChanged:) 
    name:@"kNetworkReachabilityChangedNotification" object:nil];
    [self initStatus];
    [_session resume];
    _loginButton.style = FBLoginButtonStyleWide;
    }
  3. Change the updateStatus method to check both variables.
    - (void)updateStatus
    {
    // Query the SystemConfiguration framework for
     the state of the device's network connections.
    self.remoteHostStatus = 
    [[Reachability sharedReachability] remoteHostStatus];
    self.internetConnectionStatus = 
    [[Reachability sharedReachability] internetConnectionStatus];
    NSLog(@"remote status = %d, internet status = %d", self.remoteHostStatus, 
    self.internetConnectionStatus);
    if (self.internetConnectionStatus == 
    NotReachable && self.remoteHostStatus == NotReachable) {
    //show an alert to let the user know that they can't connect...
    UIAlertView *alert = 
    [[UIAlertView alloc] initWithTitle:@"Network Status" 
    message:@"Sorry, our network guro determined that the network is not available.
     Please try again later." delegate:self cancelButtonTitle:nil 
    otherButtonTitles:@"OK", nil];
    [alert show];
    } else {
    // If the network is reachable, make sure the login button is enabled.
    _loginButton.enabled = YES;
    }
    }
I left the log statement so that you could see how the values change as the network settings are changed. In the simulator, go to network settings and disable your connections while it is running. The reachabilityChanged method is now being called as the network status changes.
Here’s the original sample project without the API Keys and Template Bundle IDs. fbconnect-iphone-reachable.zip

How to concatenate char / string on iPhone?

NSString *string = [NSString stringWithFormat:@"%@ %@", @"Hello", @"World"];
NSLog(@"%@", string);

or

NSString *string1 = @”Hello”;
NSString *string2 = @”World”;

string1 = [string1 stringByAppendingString:string2];

Capture iPhone Simulator Screenshots – Revisited – iPhone Simulator Cropper

iPhone project was looking for a tool to capture a series of screenshots for an upcoming application demo. In a Google search he first bumped into a post I wrote back in February of 2009: Capture iPhone Simulator Screenshots – Open Source Screen Capture Tool, a nice Mac tool for taking screenshots. As luck would have it, he also found another screen capture tool, one focused solely on iPhone screenshots: iPhone-Simulator Cropper.
iPhone-Simulator Cropper
This tool works by capturing the screen of the simulator runnning on your system. One really slick feature is the option to create captured images in two primary formats – first, a format suitable for upload to iTunes for your application screenshots – second, capturing a screenshot that is suitable for display on a website.
The following images show the iPhone-Simulator Cropper application, as well as two sample images captured:

iTunes Connect / App Store:

Website (iPhone Device from Apple Marketing):

2 Ways to Take Screenshots From Your iPhone

Ever wanted to know how to get great screenshots from your iPhone? It’s really easy. With the iPhone 2.0 software, you can simply hold down the Home button and press the top (on/off) button. The screen will flash and the screenshot will be saved to your iPhoto library. That’s quick and simple, for sure, but to actually use the screenshots on your computer you still have to transfer them.
You can also grab screenshots directly from your computer while plugged into your iPhone or iPod Touch. First, you have to download and install the iPhone SDK. Don’t worry, it’s free. You just have to have the desktop software tools that come with the SDK.

Open Xcode and open the Organizer window (from the Window menu). Plug in your iPhone or iPod Touch and in a few seconds, it should appear in the list of devices on the left. The first time you plug in your iPhone or iPod Touch you will be asked if you want to use that device for development.

Once you’ve got your device setup, just click the “Screenshot” tab in the Organizer window and you can capture screenshots from your device. You can capture literally any screenshot, including the lock screensaver, video as it’s playing, even as you’re holding a button down.