Wednesday, 3 February 2016

Communication between iPhone & Watch OS2

In this tutorial we will cover communication between iPhone and Watch using WatchConnectivity framework (available for Watch OS2 & onwards)

1. Create a Single View Application (you can use other application type too).

2. Click File -> New Target -> WatchKit App (Do not choose WatchKit App for watchOS 1 as it does not support WatchConnectivity framework).

3. So we do have two Targets viz. App and App Watch Extension.

4. Import the WatchConnectivity framework to both the targets.

5. In our App's ViewController.h file
#import <WatchConnectivity/WatchConnectivity.h>
add protocol <WCSessionDelegate>

6. Now in our App's ViewController.h file's viewDidLoad method:
check if WCSession is supported by our iOS, if yes then do initailize WCSession, set its delegate and activate the session as shown:

if ([WCSession isSupported]) {
        WCSession *session = [WCSession defaultSession];
        session.delegate = self;
        [session activateSession];


7. In order to send data to Watch we need to use updateApplicationContext method of WCSession.
NSDictionary containing our data to be passed to Watch can be passed to WCSession.

if ([WCSession isSupported]) {
        WCSession *session = [WCSession defaultSession];
        if (session.isReachable) {
            NSDictionary *applicationDict = [[NSDictionary alloc] initWithObjects:@[@"Value1", @"Value2"] forKeys:@[@"Key1", @"Key2"]];
            [session updateApplicationContext:applicationDict error:nil];


8. Now in App Watch Extension's InterfaceController.h file
#import <WatchConnectivity/WatchConnectivity.h>
add protocol <WCSessionDelegate>

9. To get the data passed from iPhone use WCSession delegate method:

- (void)session:(WCSession *)session didReceiveApplicationContext:(NSDictionary<NSString *, id> *)applicationContext;
applicationContext object is the NSDictionary passed from the iPhone.

Download Code: Here

Friday, 24 July 2015

payUmoney Payment Gateway Integration in iOS App (Objective C)

We have many Payment Gateways available such as Paypal, CCAvenue, Zaakpay, etc.

payUmoney is the best Payment Gateway available in India now; according to me.
I am saying this with my personal experience with payUmoney Technical Support Team.

They offer 2.9% Transaction charges without any Enrolment, Setup, AMC or other Hidden charges.

payUmoney Home Page Link: Home_Page

payUmoney Contact Details:
 5th Floor, Pearl Towers Plot 51, Sector 32 Gurgaon, 122002



Steps to integrate payUmoney gateway:

1. Create a new iOS Objective C app in XCode.
2. Open Main.storyboard in you app.
3. Add UIWebView and set its Delegate. [Screenshot 1]
4. Set Frames & Constraints as per design requirements.
5. Link UIWebView by creating IBOutlet to either .h or .m file. [Screenshot 2]
6. Signup and create an account on payUmoney. Test Envirnment: or Production Environment:
7. Follow below mentioned procedure to complete the registration process:

 Test Environment:

 Recently, payUmoney has done some modifications in test environment due to which test key-JBZaLc and salt-GQs7yium will not work anymore.

 In order to test the gateway using a test key and salt, kindly follow these steps:

     1 - Go on
     2 - Sign up as a merchant - use any of your valid email ids - kindly do not use a random email id.
     3 - Use a valid Mobile Number and for Phone/Landline No use your valid mobile number with a preceeding 0. (e.g. Mobile No: 9762159571 so the Landline No: 09762159571)
     4 - Complete the "Business Details"  - you may use PAN no. ABCDE1234F and DOB - 01/04/1990
     5 - Complete "Bank Account Details" (You may use IFSC- ALLA0212632)
     6 - Please leave the bank verification part.
     7 - Go to below mentioned location to get the Test Merchant Id :
          Seller Dashboard -> Settings -> My account -> Profile Settings

 Once you provide your test merchant id, payUmoney will approve it so that you can find your test key and salt at :
 Seller Dashboard -> Settings -> My account -> Merchant Key - Salt

 Production Environment:

 kindly register to and follow above steps with all your Genuine Bank details, contact numbers & adresses.
 Please note that the Key and Salt for Production server are different from the one we get from Test server.

8. payUmoney requires some mandatory fields to make a web-call:
    txnidkey, amount, productinfo, firstname, email, phone, surl, furl, hash, service_provider.
9. We have to create a Transaction ID which must be unique SHA512 encrypted value.
10. Take all values from user except txnid, key, surl, furl,  hash & service_provider.
11. Create a NSString by appending all the values in sequence as below:
NSString *hashValue = [NSString stringWithFormat:@"%@|%@|%@|%@|%@|%@|||||||||||%@",key,txnid1,amount,productInfo,firstname,email,Salt];
12. Use SHA512 encryption to hash the hashValue.
13. Create a NSDictionary of with all the values we have.
14. Make a POST type NSMutableURLRequest and pass the required parameters.
15. Load the NSMutableURLRequest to WebView and we are done.

Download code from Github Repo: Code

Special Thanks to:

Friday, 3 July 2015

Variable declaration in Swift

Declaration of iVar:

Let's start with declaring iVars in Swift

In Swift we can declare an iVar using keyword:
1. let - it declares an immutable iVar
2. var - it declares a mutable iVar

let myLetObject = "My immutable iVar"
So now i cannot change the value of myLetObject after it is once assigned.

var myVarObject = "My mutable iVar"
myVarObject = "Changed the value of iVar"
I can change its value at any instance.

Some examples of declaring objects:
let luckyNumber = 9
let myAge = NSInteger(27)
var myHeight = 5.5
let myImage = UIIMage(named:"MyPhoto.png")
var myName: NSString = NSString"string:Suraj Ramjan Mirajkar"
var tableView: UITableView!