Bring up UIPickerView when clicked on UIButton

We don’t add UIPickerView as subview. There is a trick to achieve this.

Create a dummy UITextField

This text field is not visible to user, is a hidden field

Read More

iOS - Working with MKMapView

Here I want to discuss about using map in iOS application

First, import MapKit

ViewController.h

Read More

Use custom font in iOS application

There are few steps to add custom font in your Xcode project.

Step 1: Add UIAppFonts to your Info.plist

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<key>UIAppFonts</key>
<array>
<string>CUSTOMFONT-BLACK.TTF</string>
<string>CUSTOMFONT-BLACKIT.TTF</string>
<string>CUSTOMFONT-BOLD.TTF</string>
<string>CUSTOMFONT-BOLDIT.TTF</string>
<string>CUSTOMFONT-EXTRALIGHT.TTF</string>
<string>CUSTOMFONT-EXTRALIGHTIT.TTF</string>
<string>CUSTOMFONT-IT.TTF</string>
<string>CUSTOMFONT-LIGHT.TTF</string>
<string>CUSTOMFONT-LIGHTIT.TTF</string>
<string>CUSTOMFONT-REGULAR.TTF</string>
<string>CUSTOMFONT-SEMIBOLD.TTF</string>
<string>CUSTOMFONT-SEMIBOLDIT.TTF</string>
</array>

Read More

Wordpress form submission get 404

Have you ever face a problem, when there is GET request, it shows the form properly. However when there is POST request, there are 2 situations:

Read More

Remove unwanted/dummy character in C language

I’ve encounter this issue in RSA decryption (RSA_private_decrypt)

1
2
int result_length = RSA_private_decrypt(64, (unsigned char*)crypt_chunk, (unsigned char *)result_chunk, rsa_privateKey, RSA_PKCS1_PADDING);
printf("Result chunk: %s\nChunk length: %d\n", result_chunk, result_length);

Read More

How iPhone communicate with server in PHP

I have few friends as me about this.

How iOS can retrieve/update from/to MySQL/MSSQL database?

There are 2 parts:- Server side and Client side

Read More

Invoke a method call from AppDelegate via Notification

Think of a scenario here:

You have a class LoginViewController, while Facebook login api call is keep on AppDelegate.m, and you want to perform some action after success login via Facebook.

Read More

Get JSON using PHP cURL from web service

This example is to show how to detect user’s country

For GET request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

// set HTTP header
$headers = array(
'Content-Type: application/json',
);

// query string
$fields = array(
'key' => '<your_api_key>',
'format' => 'json',
'ip' => $_SERVER['REMOTE_ADDR'],
);
$url = 'http://api.ipinfodb.com/v3/ip-country?' . http_build_query($fields);

// Open connection
$ch = curl_init();

// Set the url, number of GET vars, GET data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// Execute request
$result = curl_exec($ch);

// Close connection
curl_close($ch);

// get the result and parse to JSON
$result_arr = json_decode($result, true);

print_r($result_arr);
/*
* output:
* Array
* (
* [statusCode] => "OK",
* [statusMessage] => "",
* [ipAddress] => "123.13.123.12",
* [countryCode] => "MY",
* [countryName] => "MALAYSIA",
* )
*/
?>

Read More

iOS - Get the radius of MKMapView

Some time we might have too much locations want to show to user, unfortunately, it may cause some performance issue if load all locations in one short.

Read More

iOS - Handle UISearchBar keyboard show/hide issue

I have experienced that when you focus on UISearchBar, the keyboard occupied half of the screen. The question is, “Under what condition should the keyboard hide?”.

Read More