Posts

Calling depending Web Services + dispatch_group_t in iOS

What is the best approach to call the web services in a chain?

Create a dispatch group

dispatch_group_t serviceGroup;
Call the first function/web service
-(void)callFirstWebService { serviceGroup = dispatch_group_create();
//Call 1st web service here, In the completion block, call the second method which you want to perform serially [self callSecondWebService];

dispatch_group_notify(serviceGroup,dispatch_get_main_queue(),^{ // Won't get here until everything has finished NSLog(@"All Tasks finished"); //Reload table or another task which you want to perform when both service finished }); }

-(void) callSecondWebService{ dispatch_group_enter(serviceGroup); //Call 2nd web service and in the completion block, write the below code
dispatch_group_leave(serviceGroup); }

//*******************Theoretical Explantion*****************
Create a method where you want to call webservice. Depending on response, you want to call another webservice/method. After completion of all task, you want to perform las…

Semaphore | Delay splash screen in iOS + Objective C

How to wait for an asynchronously dispatched block to finish?How to integrate semaphore in iOS?How to delay splash screen for longer time, so that developer can prefetch or execute something before start of iOS App.
The answer of all the above questions is SEMAPHORE.  A semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system such as a multiprogramming operating system. 
Suppose you want to perform some task before root view controller is shown to user.  Goto AppDelegate's method didFinishLaunchingWithOptions, create a method as below:- 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     [self performTaskToDelaySplash]; }
-(void) performTaskToDelaySplash {     dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); //1. Create semaphore //Perform your task here, i.e Any webservice call or any database operation
         dispatch_semaphore_signa…

MySQL connect utility in Mac OS

Using DbVisualizer, we can connect to MySQL database on Mac.
Download the installer (select appropriate Platform & Installer Type) here
DbVisualizer offers setup for following platforms:-
Windows 32 bitWindows 64 bitMac OS XLinuxUNIX

Play youtube video in iOS app

Youtube video can be played in iOS app using webview. MPMoviePlayerController is not able to open youtube video automatically. Integrate the below script to show thumbnail, clicking on it the video will play in full screen.


NSString *url = @"https://www.youtube.com/embed/8aMHGC6A5zc"; NSString* embedHTML = @"\     <html><head>\     <style type=\"text/css\">\     body {\     background-color: transparent;\     color: white;\     }\     </style>\     </head><body style=\"margin:0\">\     <iframe id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \     width=\"%0.0f\" height=\"%0.0f\" frameborder=\"0\" feature=player_detailpage allowfullscreen></iframe>\     </body></html>"; NSString* html = [NSStringstringWithFormat:embedHTML, url, self.view.frame.size.width, 200.0];
    [webviewloadHTMLString:html baseURL:nil];


///*******************A…

Working with MongoDB

Generate a new SSH key (https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/). If you have already ssh key generated at mac, then copy the key using:-
pbcopy < ~/.ssh/id_rsa.pub
Pass the key to your server developer (DevOps). He will give access to a server, for eg: http://192.168.70.55:8080When he add your key, then open the terminal and type command:- ssh root@192.168.70.55 You will see this in terminal:-The authenticity of host '192.168.70.55 (192.168.70.55)' can't be established. RSA key fingerprint is SHA256:supbA7wsdvc3xXnVyHvj7fXGjlpCpt1kigJrljR4. Are you sure you want to continue connecting (yes/no)? Enter yes Enter your server addresss (http://192.168.70.55:8080/) in your browser and it connects and start working. Mongo official reference for queries:- https://docs.mongodb.com/v3.0/reference/method/db.collection.update/#update-parameter

How to show activity indicator in watch kit

To show loading indicator in watch kit without using any third party, follow the below steps:- Download the images here and add them in watch kit at xcassets (MyPWatch WatchKit App -> Assets.xcassets)Add the WKInterfaceImage (named imageLoading) to your 
WKInterfaceController Show loading indicator as belowself.imageLoading.setImageNamed("Activity") self.imageLoading.startAnimatingWithImages(in: NSMakeRange(1, 15), duration: 3.0, repeatCount: 0) To hide the indicator, do as below:- self.imageLoading.stopAnimating() self.imageLoading.setHidden(true)