2010年12月2日 星期四

[IPhone] Send SMS sample with IPhone

Introduction

I will demo some sample to present how to send SMS in iphone programming.

Sample 1

The easiest way is this demo.

[[UIApplication sharedApplication] openURL: @"sms:12345678"];



HTML links:  
<a href="sms:" mce_href="sms:">Launch Text Application</a>
<a href="sms:1-408-555-1212" mce_href="sms:1-408-555-1212">New SMS Message</a>

Native application URL strings:

sms:
sms:1-408-555-1212



Sample 2

We can use MessageUI Framework and MFMessageComposeViewController to send SMS.

-(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];
}
}


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];
}




Sample 3

This is a full sample code for MFMessageComposeViewController.


//  SMS2ViewController.h
// SMS2
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>
@interface SMS2ViewController : UIViewController <MFMessageComposeViewControllerDelegate>
{
UILabel *message;
}
@property (nonatomic, retain) UILabel *message;
-(void)displayComposerSheet;
@end



//  SMS2ViewController.m
// SMS2
#import "SMS2ViewController.h"
@implementation SMS2ViewController
@synthesize message;
/*
// The designated initializer.
Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
// Custom initialization
}
return self;
}
*/
// Implement loadView to create a view hierarchy programmatically, without using a nib.
/*
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *smsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
smsButton.frame = CGRectMake(97.0, 301.0, 125.0, 37.0);
smsButton.adjustsImageWhenDisabled = YES;
[smsButton setTitle:@" Send SMS" forState:UIControlStateNormal];
[smsButton setTitleColor:[UIColor colorWithWhite:0.000 alpha:1.000] forState:UIControlStateNormal];
[smsButton setTitleShadowColor:[UIColor colorWithWhite:0.000 alpha:1.000] forState:UIControlStateNormal];
[smsButton addTarget:self action:@selector(displayComposerSheet) forControlEvents:UIControlEventTouchUpInside];
message = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 360.0, 280.0, 29.0)];
message.frame = CGRectMake(20.0, 360.0, 280.0, 29.0);
message.adjustsFontSizeToFitWidth = YES;
message.hidden = YES;
message.text = @"";
message.userInteractionEnabled = NO;
[self.view addSubview:smsButton];
[self.view addSubview:message];
}
-(void)displayComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
icker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:@"123456789"];
// your recipient number or self for testing
picker.body = @"test from OS4";
[self presentModalViewController:picker animated:YES];
[picker release];
NSLog(@"SMS fired");
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
message.hidden = NO;\
switch (result)
{
case MessageComposeResultCancelled:
message.text = @"Result: canceled";
NSLog(@"Result: canceled");
break;
case MessageComposeResultSent:
message.text = @"Result: sent";
NSLog(@"Result: sent");
break;
case MessageComposeResultFailed:
message.text = @"Result: failed";
NSLog(@"Result: failed");
break;
default:
message.text = @"Result: not sent";
NSLog(@"Result: not sent");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload
{
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
}
@end

2010年11月28日 星期日

[IPhone] Remind to rank/review sample code

Introduction

How can we remind user to review or rank in App?
We can show a alert box to remind user to review, I writed a sample code using singleton to remind user.

How to use

[[CloudReview sharedReview]reviewFor:395519376];

CloudReview.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface CloudReview : NSObject {
int m_appleID;
}

+(CloudReview*)sharedReview;
-(void) reviewFor:(int)appleID;
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

@end


CloudReview.m
#import "CloudReview.h"


@implementation CloudReview

static CloudReview* _sharedReview = nil;

+(CloudReview*)sharedReview
{
@synchronized([CloudReview class])
{
if (!_sharedReview)
[[self alloc] init];

return _sharedReview;
}

return nil;
}

+(id)alloc
{
@synchronized([CloudReview class])
{
NSAssert(_sharedReview == nil, @"Attempted to allocate a second instance of a singleton.");
_sharedReview = [super alloc];
return _sharedReview;
}

return nil;
}

-(void)reviewFor:(int)appleID
{
m_appleID = appleID;
BOOL neverRate = [[NSUserDefaults standardUserDefaults] boolForKey:@"neverRate"];
if(neverRate != YES) {
//Show alert here
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"rate_title",@"Rate My Appication")
message:NSLocalizedString(@"rate_main",@"Please Rate my Application")
delegate: self
cancelButtonTitle:NSLocalizedString(@"rate_cancel",@"Cancel")
otherButtonTitles: NSLocalizedString(@"rate_now",@"Rate Now"),
NSLocalizedString(@"rate_never",@"Never Rate"), nil];
[alert show];
[alert release];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Never Review Button
if (buttonIndex == 2)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"neverRate"];
}
// Review Button
else if (buttonIndex == 1)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"neverRate"];
NSString *str = [NSString stringWithFormat:
@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",
m_appleID ];
NSLog(str);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
}

@end

2010年11月10日 星期三

[Design Pattern] MVC pattern



Model–View–Controller (MVC) is a software architecture,[1] currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing and maintenance of each (separation of concerns).

The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.

The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.

The controller receives input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and viewport to perform actions based on that input.

An MVC application may be a collection of model/view/controller triads, each responsible for a different UI element. The Swing GUI system, for example, models almost all interface components as individual MVC systems.

MVC is often seen in web applications where the view is the HTML or XHTML generated by the app. The controller receives GET or POST input and decides what to do with it, handing over to domain objects (i.e. the model) which contain the business rules and know how to carry out specific tasks such as processing a new subscription, and which hand control to (X)HTML-generating components such as templating engines, XML pipelines, AJAX callbacks, etc.

The model is not a database: the 'model' in MVC is both the data and the business/domain logic needed to manipulate the data in the application. Many applications use a persistent storage mechanism such as a database to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the model. Models are not data access objects; however, in very simple apps that have little domain logic there is no real distinction to be made. Active Record is an accepted design pattern which merges domain logic and data access code - a model which knows how to persist itself.

[Design Pattern] Facade Pattern


The facade pattern is a software engineering design pattern commonly used with Object-oriented programming. (The name is by analogy to an architectural facade.)

A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can:

make a software library easier to use, understand and test, since the facade has convenient methods for common tasks;
make code that uses the library more readable, for the same reason;
reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system;
wrap a poorly-designed collection of APIs with a single well-designed API (as per task needs).


2010年10月28日 星期四

[IPhone] Fight Bingo Lite V1.0

Category top free 100 in 15 countries.
In Taiwan, Fight Bingo Lite got top 7.
Thank you very much.^^



The Fight Bingo Lite was on sales.
Simple AI with Lite version.

http://itunes.apple.com/us/app/fight-bingo-lite/id399638337?mt=8



2010年10月18日 星期一

[iPhone] Bingo Fight v1.1 update

V1.1.1 will fix this bug.
V1.1.1 was already in review.
Bug report:
Found a bug, when palyer won then click new game.
Touch board could not response.
Click new game again will fix it.
I will fix thisbug at next version.
Thanks very much.

Bingo Fight update to v1.1
1. Add fighter's fighting animation.
2. You can see two people fight with fire ball.

download link

Promotional Codes:
A6RWM3MHJNTR
69W36JX3MPM6
EAM3W9WJ93LL
ENNFXJ4PMH67
JL7MP3R3N4J6
JR673LW63L7W
9EA3EW3KXR33
9ENKF3XAE4FY
TWK6WXX9RHKN
LNAF6EKKMFEM







2010年10月6日 星期三

[IPhone] My first iphone app(Bingo Fight)

It's my first one Iphone Game (Bingo Fight) on sale now. The idea is from an Bingo Game that I made,
just simple rules that just get five lines to win.
Download with the link if interested as a treat to me for drinking.

Thanks Page Huang to support.

How to Play:
You must touch Left Board with number, then computer will cohice a number.
Five numbers to get a line.
If you get five lines first, you will win the game.

Promotional Codes:
X3KPAT9R4HA7
PH9KT3L4LEAY
TEMMW94ML4MA
NF7FHRYJ4YXJ
7ETX9TJ6RXHK

download link