Thursday, June 21, 2012

Capture screenshots on Mac OS

Sau đây là 3 cách dùng tổ hợp phím để chụp màn hình và lưu nhanh thành file ảnh .png vào Desktop:

1. Chụp nguyên màn hình
Command + Shift + 3,
rồi buông ra.

2. Chụp một vùng trên màn hình
Command + Shift + 4
, sau đó vẽ một hình chữ nhật khu vực cần chụp.

3. Chụp một thành phần giao diện (không dính nền, đẹp, chỉ dành cho Leopard)

Giữ Command + Shift + 4, trong khi giữ 3 phím đó, ta nhấn thêm phím Spacer bar (thanh dài), con chuột sẽ biến thành hình Camera, ta di chuyển đến thành phần nào (thí dụ cửa sổ, menu, icon, ...) thì sẽ chụp
thành phần đó và lưu lại thành file.


Thí dụ ta có thể chụp hình chiếc máy tính (Widget) như thế này mà không dính nền, không dính Wallpaper bằng cách thứ 3:


[IMG]


File ảnh được lưu xuống Destkop với định dạng PNG. Muốn chuyển sang định dạng khác bạn cần vào Terminal và nhập lệnh:
Code:
defaults write com.apple.screencapture type <định dạng ảnh>
killall SystemUIServer
VD:
defaults write com.apple.screencapture type jpg
killall SystemUIServer

-> file chụp ảnh màn hình sẽ có dạng JPG

Build file .ipa with xCode 4.3

Để chuyển 1 file .app sang .ipa đầu tiên các bận cần có là 1 file .app, trong hướng dẫn mình sử dụng file Tuvi.app

1. Mở xcode len
2. Menu Window\Organizer





3. Chọn File Tuvi trong Project & Resource 
4. Trong iPhone Development, chọn Archieved Applications
5. Trong phần sharing, nhấn vào nút Share Application...


6. Sau cùng là nhập vào tên bạn cần save as & đường dẫn




7. Sau khi save xong bạn sẽ có thêm 1 file Tuvi.ipa ở đường dẫn đã save

Wednesday, June 20, 2012

iPhone Tutorial: How to send In-App SMS


Officially, iPhone OS 4 is out of NDA and I can’t write a post on this. If you have been reading my blogs, you might already know how to send a in-app email Sending a in-app SMS is very similar to this, but with subtle differences.
Prior to iPhone OS 4, developers have to depend on
[[UIApplication sharedApplication] openURL: @"sms:12345678"];
So, Let’s get started.

The problem with this is not just that it closes your app, but there is no way to specify the body content of the SMS. Secondly, you are restricted to send the SMS to only one person. However, with the new MessageUI SMS controller, you can send SMS to multiple people at the same time. You can also pre-populate the SMS body field.
Developers of famous apps like Whatsapp Messenger, copy the SMS text content to clipboard and open the SMS app to allow users to paste the content. But with this newly allowed In-App SMS sheet, users can send SMS without quitting the app.
Step 1:


Import the MessageUI Framework into your project and #import the header file into the “.h” file of your controller where you want to open the In-App SMS sheet.

Step 2:

You might already have a button handler IBAction where you want to send the SMS. If not create a Button on your XIB file and write IBActions for it.

Step 3:

The real code
-(IBAction) sendInAppSMS:(id) sender
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Hello from Mugunth";
controller.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
The most important part here is the line [MFMessageComposeViewController canSendText].
When sending a in-app email, you can choose to ignore this (atleast as of now) because most of the devices would have upgraded to iPhone OS 3 and all those devices would have the ability to send in-app email. However, the same doesn’t apply to SMS. Remember that even if a device is running iPhone OS 4, if it’s an iPod touch, it will never be abel to send SMS within app.
In this case, I have used a if condition to send the SMS. Practically speaking, you should enable/disable the button the user taps to send the sms based on this. You can add the code that does this in your viewDidLoad method.
Secondly, you have to set the messageComposeDelegate to self and not delegate. If you set the controller.delegate to self, you will not get the didFinishWithResult callback and the In-App SMS sheet will not close.

Step 4:

Implement Delegate Callbacks.
In your header file, implement the callbacks, MFMessageComposeViewControllerDelegate and UINavigationControllerDelegate. If you don’t you will get a warning at the line,


controller.delegate = self;
You have to handle a callback method of MFMessageComposeViewControllerDelegate so as to dismiss the modal view controller.
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Unknown Error"
delegate:self cancelButtonTitle:@”OK” otherButtonTitles: nil];
[alert show];
[alert release];
break;
case MessageComposeResultSent:
 
break;
default:
break;
}
 
[self dismissModalViewControllerAnimated:YES];
}
That’s it. Your app should now be able to send SMS using the new Message UI sheet.

Where the heck is MMS in this tutorial?

As on date, the MFMessageComposeViewController doesn’t support sending MMS. The controller.body is a NSString and setting a NSData pointer obviously crashes the app. Hopefully, one day, Apple will allow sending In-App MMS and I’ll probably blog about that too…