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

ScreenCast of app

ScreenCast


1. Login Screen:
Hit Login to Facebook button.








2. Facebook Login Screen:
Insert your Facebook credentials to single sign on.
Once you are signed you no need to insert the FB credentials each time you get back to the app.







3. Facebook Authorization Screen:
We need your permission to fetch your FB details like your mail id, fb id, photo albums, etc. to load it in our app.
By hitting "Ok" button you authorize us to use your details in our app.
In case you hit "Cancel" button you will be navigated to Login Screen.






4. Login Screen:
Once you have authorized us to use your FB details we display your FB profile picture on the Login Screen along with your FB user name.
And as soon as we get the your FB Photo Albums we launch the Album List Screen.



5. Album List Screen:
Here we load your photo albums details like album cover photo, album name, album created time.
On clicking/selecting any one album from the provided list we navigate you to the Photos Grid Screen.






6.  Photos Grid Screen:
Here you get all the photos thumbnails.




7. Photos Slider/Viewer Screen:
Here can checkout the photos in full screen mode, you can zoom in/out by pinching action.
You can swipe left and right to checkout the next and previous photos in the current album.






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:
 Address: 
 5th Floor, Pearl Towers Plot 51, Sector 32 Gurgaon, 122002

 Phone: 
 0124-6624956,
 0124-6624970

 Email: 
 techsupport@payumoney.com


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: http://test.payumoney.com/ or Production Environment: https://www.payumoney.com/
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 http://test.payumoney.com/
     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 https://www.payumoney.com/ 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:
Stackoverflow_Link
payUmoney_Link