14 Feb 2017

ViewController Containment & Storyboard reference useful Links…

Design Patterns… MVVM & Singleton useful Links...



Design Patterns…  MVVM & Singleton useful Links...


MVVM…




Singleton…

  1. http://stackoverflow.com/questions/15383452/objective-c-sample-singleton-implementation
  2. https://code.tutsplus.com/articles/design-patterns-singletons--cms-23886

3D Animations useful Links & Colors…

Animations & About Frames useful Links...


Animations useful Links...












Frames…


10 Feb 2017

UIImagePickerController & NSUserDefaults Full Code…


UIImagePickerController & NSUserDefaults Full Code…



Add it in Source Code of info.plist...

(<key>NSPhotoLibraryUsageDescription</key>
    <string>$(PRODUCT_NAME) uses photos</string> )



StorYboard...



#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *firstNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *lastNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *ageTextField;
@property (weak, nonatomic) IBOutlet UIImageView *contactImageView;

- (IBAction)saveBtn:(id)sender;
- (IBAction)chooseImageBtn:(id)sender;

@end


#import "ViewController.h"

@interface ViewController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    
    // Get the stored data before the view loads
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSString *firstName = [defaults objectForKey:@"firstName"];
    NSString *lastName = [defaults objectForKey:@"lastname"];
    
    NSInteger age = [defaults integerForKey:@"age"];
    NSString *ageString = [NSString stringWithFormat:@"%li",(long)age];
    
    NSData *imageData = [defaults dataForKey:@"image"];
    UIImage *contactImage = [UIImage imageWithData:imageData];
    
    // Update the UI elements with the saved data
    _firstNameTextField.text = firstName;
    _lastNameTextField.text = lastName;
    _ageTextField.text = ageString;
    _contactImageView.image = contactImage;
    
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)saveBtn:(id)sender {
    
    // Hide the keyboard
    [_firstNameTextField resignFirstResponder];
    [_lastNameTextField resignFirstResponder];
    [_ageTextField resignFirstResponder];
    
    // Create strings and integer to store the text info
    NSString *firstName = [_firstNameTextField text];
    NSString *lastName  = [_lastNameTextField text];
    NSInteger age = [[_ageTextField text] integerValue];
    
    // Create instances of NSData
    UIImage *contactImage = _contactImageView.image;
    NSData *imageData = UIImageJPEGRepresentation(contactImage, 100);
    
    
    // Store the data
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    [defaults setObject:firstName forKey:@"firstName"];
    [defaults setObject:lastName forKey:@"lastname"];
    [defaults setInteger:age forKey:@"age"];
    [defaults setObject:imageData forKey:@"image"];
    
    [defaults synchronize];
    
    NSLog(@"Data saved");
    
}

- (IBAction)chooseImageBtn:(id)sender {
    
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picker animated:YES completion:nil];
    
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    _contactImageView.image = image;
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}
@end

8 Feb 2017

Google Sign in Integration into iOS App with Clear Steps n Images…


Google Sign in Integration into iOS App with Clear Steps n Images…


Google Sign in Integration into iOS App Clear Steps…


  1. Create A new Project with name GoogleSignInApp (Existed or Create depends on…) and close the project.
  2. Open terminal with (Command + Space) and type Terminal
  3. Terminal opened First Install Cocoa  pods using Command $ sudo gem install cocoapods ( if already installed no need…)
  4. Then in Terminal Go to your project Directory by using the Command   cd

Screen Shot 2017-02-08 at 12.01.35 PM.png

5.Then in terminal pod init
6.open podfile

Screen Shot 2017-02-08 at 12.03.52 PM.png
7. pod file created in project and a new window opened with the title pod file as shown below.
Screen Shot 2017-02-08 at 12.04.48 PM.png
8.Add pod 'Google/SignIn' as shown below(note: use (Ctrl + “) to get straight quote like this   ’  )
Screen Shot 2017-02-08 at 12.10.34 PM.png9. Then Save pod file by using (command + S) and close pod file using (command +W)
10. Now in already opened Terminal   pod install  as shown below.. pods installed successfully in our project…
Screen Shot 2017-02-08 at 12.15.06 PM.png
11. Close terminal (command  + W)
12. Now open Project and Check pods folder to see added pods or not..?
13. Open Workspace created in our project
14. once see this Link…
15. Then Click on GET A CONFIGURATION FILE or Click below Link..
Screen Shot 2017-02-08 at 12.25.04 PM.png
16. Give App name (Its not necessary to give your app name…)
17. iOS Bundle ID (Which is available in our project)
18. Your country
19. Then CONTINUE TO Choose  and configure services
20. Enable Google sign-In as shown below…
Screen Shot 2017-02-08 at 12.31.20 PM.png
21. Then CONTINUE TO Generate configuration files
Screen Shot 2017-02-08 at 12.35.46 PM.png
Screen Shot 2017-02-08 at 12.36.14 PM.png
22. Download GoogleService-Info.plist (which downloaded into downloads)
23. Then Click Continue Adding Sign-In
24. Drag the GoogleService-Info.plist file you just downloaded into the root of your Xcode project
Screen Shot 2017-02-08 at 12.41.34 PM.png
26. In the Project > Target > Info > URL Types panel, create a new item and paste your REVERSED_CLIENT_ID into the URL Schemes field. You can find your REVERSED_CLIENT_ID in the GoogleService-Info.plist file.
27. Also in the Project > Target > Info > URL Types panel, create a new item and type your bundle identifier in the URL Schemes field.
28. In your app delegate's .h file, declare that this class implements the GIDSignInDelegate protocol.

#import <Google/SignIn.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, GIDSignInDelegate>

29. In your app delegate's application:didFinishLaunchingWithOptions: method, configure the GGLContext shared instance and set the sign-in delegate.

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  NSError* configureError;
  [[GGLContext sharedInstance] configureWithError: &configureError];
  NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

  [GIDSignIn sharedInstance].delegate = self;

  return YES;
}

30. Implement the application:openURL:options: method of your app delegate. The method should call the handleURL method of the GIDSignIn instance, which will properly handle the URL that your application receives at the end of the authentication process.
- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary *)options {
  return [[GIDSignIn sharedInstance] handleURL:url
                             sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                    annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}

For your app to run on iOS 8 and older, also implement the deprecated application:openURL:sourceApplication:annotation: method.

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
  return [[GIDSignIn sharedInstance] handleURL:url
                             sourceApplication:sourceApplication
                                    annotation:annotation];
}

31.In the app delegate, implement the GIDSignInDelegate protocol to handle the sign-in process by defining the following methods:

*** This Code is to get user Details from Google with Google Sign in****

- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
     withError:(NSError *)error {
  // Perform any operations on signed in user here.
  NSString *userId = user.userID;                  // For client-side use only!
  NSString *idToken = user.authentication.idToken; // Safe to send to the server
  NSString *fullName = user.profile.name;
  NSString *givenName = user.profile.givenName;
  NSString *familyName = user.profile.familyName;
  NSString *email = user.profile.email;
  // ...
}

- (void)signIn:(GIDSignIn *)signIn
didDisconnectWithUser:(GIDGoogleUser *)user
     withError:(NSError *)error {
  // Perform any operations when the user disconnects from app here.
  // ...
}


32. Next, you will add the Google Sign-In button so that the user can initiate the sign-in process. Make the following changes to the view controller that manages your app's sign-in screen:                                                                                                                         In the view controller's .h file, add the Google Sign-In interface and declare that this class implements the GIDSignInUIDelegate protocol.

#import <Google/SignIn.h>


@interface ViewController : UIViewController <GIDSignInUIDelegate>

  1. Add a GIDSignInButton to your storyboard, XIB file, or instantiate it programmatically. To add the button to your storyboard or XIB file, add a View and set its custom class to GIDSignInButton.
If you want to customize the button, do the following:
  • In your view controller's .h file, declare the sign-in button as a property.
    @property(weak, nonatomic) IBOutlet GIDSignInButton *signInButton;
  • Connect the button to the signInButton property you just declared.
  • Customize the button by setting the properties of the GIDSignInButton object.

**** in IBOutlet Write below Code****

  [[GIDSignIn sharedInstance] signIn];


33. You can use the signOut method of the GIDSignIn object to sign out your user on the current device, for example:

- (IBAction)didTapSignOut:(id)sender {
  [[GIDSignIn sharedInstance] signOut];
}


2 Feb 2017

Xcode iOS project only shows “My Mac 64-bit” but not simulator or device...




Xcode iOS project only shows “My Mac 64-bit” but not simulator or device...




1.   
I figured it out. I had to edit the scheme (Product->Scheme->Edit Scheme...), and for some reason no executable was selected. I chose my app, saved and now I have my simulator and device options back.


2. 
This is basically happen, when you change your project name or something like that. The solution is, you have to select the right "Scheme" for your project. Here is the solution : 
After open your project :
  1. Go to "Product" from upper menu
  2. Select "Scheme" from the list
  3. Then select "Manage Scheme"
  4. Now no matter your "Project Name" is listed here or not just click on "Autocreate Schemes Now" from the upper-right side of the window.
  5. Press "ok", now your project rebuild and you can find the "Simulator List" on the top.

Main-differences-between-soap-and-restful-web-services...



Main-differences-between-soap-and-restful-web-services...


  • REST stands for Representational State Transfer where as SOAP stands for Simple Object Access Protocol.
  • SOAP defines its own security where as REST inherits security from underlying transport.
  • SOAP doesnot support error handling but REST has built-in error handling.
  • REST is lightweight and does not require XML parsing. REST can be consumed by any client, even a web browser with Ajax and Javascript. REST consumes less bandwidth, it does not require a SOAP header for every message.
    • REST is useful over any protocol which provide a URI. Ignore point 5 for REST as mentioned below in the picture.
SOAP vs REST

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0