Tutorial: Install Monkey Talk in less than 30 minutes and benefit from it

9 11 2013

Each Android / iOS developer should use Monkey Talk, not only for testing purposes, but also to make his life easier. Each developer knows how often one must go through the same path while developing an app – so it’s not just for testers.

With Monkey Talk you can easily record script with repeatable steps and let it do it for you. Meanwhile you can just take another sip of coffe, watching how it clicks on its own.

This post shares two links that are enough to follow to install and configure MonkeyTalk.

1. How to install Monkey Talk?

Here is very solid step by step instruction how to install monkey Talk.

2. Connect to your Android / iOS device

When connecting to an emulator the case is simple, but when you want to connect to physical device, it should be in the same WiFi network. You just need to enter the IP address in Monkey Talk IDE. Here is the description how to do it.

Did I help you?

I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality Donate Button with Credit Cards Thank You!





iOS tutorial: Send SMS programmatically

31 08 2013

iOS is very strict when it comes to using phone capabilities in applications. It limits usage because of security reasons, so in fact, as an iPhone application developer you can’t send SMS in background or listen for incoming SMS messages. The only solution to send SMS is to initiate the built in SMS application where user can click to send message (however application can preset the SMS receiver and body). This is what I show in this tutorial:

1. Import MessageUI

Add import statement in header file:

#import <MessageUI/MessageUI.h>

2. Use delegate in header

in your header file, declare the delegate as:

<MFMessageComposeViewControllerDelegate>

3. Initiate the send SMS request

Depending on your application logic, you can use this method in various places. In my case this is initiated on button click. ‘body‘ param is message content.

- (void) sendSMS:(NSString*)body{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewControlleralloc] init];
    if([MFMessageComposeViewControllercanSendText])
    {
        NSString *num = [[NSUserDefaultsstandardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];

        controller.body = body;
        controller.recipients = [NSArray arrayWithObjects:@"1(234)567-8910", num, nil];
        controller.messageComposeDelegate = self;
        [selfpresentViewController:controller animated:YEScompletion:nil];
    }
}

4. React on user’s confirmation

Code from sendSMS method will open SMS application with prepared SMS message and confirmation and cancellation button. To react on these button clicks, you have to implement delegate method:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
    NSString *num = [[NSUserDefaultsstandardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];
    NSLog(@"Some result received: %u, %@", result, num);
    [controller dismissViewControllerAnimated:YEScompletion:nil];
}

Is that really not possible?

More advanced phone actions are possible on Jailbroken devices and by using undocumented APIs, but Apple will not approve such application on AppStore.

And on Android?

In Android the situation is different. Developer is free to use all phone features including sending SMS in background, listening for incoming SMS, calls, initiating calls etc. It trusts user that if he install app he agrees that it may use such features on his device.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





iOS Tutorial: make call from app programatically

9 02 2013

Making call from iOS requires just two lines of code. These will make call without asking a user, and after the call has ended, the control will not come back to your app (see how to come back to app in further section)

Make a call initiated from app

- (void) dialNumber:(NSString*) number{
	number = [@"tel://" stringByAppendingString:number];
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:number]];
}

Notice, that the number string should contain digits only.

Come back to your app after call has ended

The prefix:

@"telprompt://"

used instead of prefix:

@"tel://"

in phone number URL will cause two things:

  • user will be prompted if he wants to make a call
  • after the call, the control will come back to your app

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





iOS tutorial: hide keyboard after return / done key press in UITextField

2 02 2013

When user finished editing text in UITextField it is good practice to hide keyboard after Done / Return key press. Another way of hiding keyboard is touch detected anywhere outside the UITextField. Both solutions are described below

1. Hide keyboard after Done / Return button press

To detect the confirm button press you need to implement UITextFieldDelegate protocol’s optional method textFieldShouldReturn:. So in header file add protocol declaration:

@interface MyViewController : UIViewController <UITextFieldDelegate>

Point the delegate that will handle protocol’s events in viewDidLoad():

self.playerNameField.delegate = self;

And in implementation file implement textFieldShouldReturn:

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if (theTextField == self.playerNameField) {
        [theTextField resignFirstResponder];
    }
    return YES;
}

This will resignFirstResponder (means: hide keyboard) for playerNameField.

2. Hide keyboard after touch outside of UITextField

This is somehow separate to previous point, however also hides the keyboard when it is not needed. To do it you need to detect the touch on the screen. There is method in UIResponder that you should override to be notified about touch event:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    //hides keyboard when another part of layout was touched
    [self.view endEditing:YES];
    [super touchesBegan:touches withEvent:event];
}

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





iOS tutorial: Using NSUserDefaults

26 01 2013

NSUserDefaults are meant to persist small amounts of data in Key-Value convention on iPhone (same as SharedPreferences on Android).

The idea is to save some object or primitive under the key. Objects that can be stored are for example of type NSString or NSArray. These will be accessible from anywhere in your application, and will persist after the application is closed. You should not use it for storing data larger than 500kb or custom Objects.

You can store there for example user’s settings or preferences, like user’s name or email. Technically it is stored in XML or binary file on the file system, however it is conveniently wrapped in SDK enabling you to call it in one line. That is how you use it:

1. Store value in NSUserDefaults

[[NSUserDefaults standardUserDefaults] setObject:@"John" forKey:@"USER_NAME_KEY"];

2. Read stored value from NSUserDefaults

NSString *name = [[NSUserDefaults standardUserDefaults] stringForKey:@"USER_NAME_KEY"];

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





iOS tutorial: play sound

19 01 2013

AudioToolbox in iOS is suitable for playing short system sounds in apps (if you need another types of sounds read this). To play sound in iOS app with AudioToolbox you have to do the following:

1. Add AudioToolbox framework to your application

Click on your project, navigate to Targets -> Build Phases -> Link Binary With Libraries -> Click ‘+’ sign -> find AudioToolbox.framework

Adding AudioToolbox framework

Adding AudioToolbox framework

2. Import AudioToolbox.h in your header file

just add this import statement:

#import <AudioToolbox/AudioToolbox.h>

3. Add audio files to the project folder

Drag audio files to the project folder:

Add audio files

Add audio files

4. Add SystemSoundID iVar

In implementation file add variable in the @interface section at the beginning of file. You can add more variables if you need more audio files to be played.

@interface MyViewController (){
    SystemSoundID soundClick;
}

5. Initialize audio files

You can init files in various places. In my example I do it in viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];
    //find URL to audio file
    NSURL *clickSound   = [[NSBundle mainBundle] URLForResource: @"click" withExtension: @"wav"];
    //initialize SystemSounID variable with file URL
    AudioServicesCreateSystemSoundID (CFBridgingRetain(clickSound), &soundClick);
}

6. Play audio file

Audio is played with one line invocation. Put it anywhere, where you need to play sound.

AudioServicesPlaySystemSound(soundClick);

7. Dispose system sound

Some clanup in viewDidUnload:

- (void)viewDidUnload {
	AudioServicesDisposeSystemSoundID(soundClick);
}

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!





iOS tutorial: progress indicator on status bar

5 01 2013

Here I will demonstrate how to show progress indicator on iPhone’s status bar. It is standard user interface element, so it is self explanatory to the user and extremely simple to develop.

Use it to indicate that some processing is taking place (for example network communication). This is how it is going to look like:

Status bar progress indicator

Status bar progress indicator

1. Show progress indicator

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

2. Hide progress indicator

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!








%d bloggers like this: