Saturday, October 31, 2015

Twitter Integration in iOS

Twitter Integration using SLRequest 

 1) Ask user to access its twitter account

  ACAccountStore *accountStore = [[ACAccountStore alloc] init];  
   ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];  
   [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {  
     if(granted) {  
            //User allowed to access account  
     }}];  

2) Get all twitter accounts from list

 ACAccountStore *store = [[ACAccountStore alloc] init];  
   ACAccountType *AccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];  
  NSArray *accountsArray = [store accountsWithAccountType:AccountType];  

3)get particular Account from Accounts array.

 -(ACAccount *)getTwitterAccount:(NSString *)aStrUserName  
 {  
   ACAccountStore *store = [[ACAccountStore alloc] init];  
   ACAccountType *AccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];  
   __weak ACAccount *selAccount = nil;  
   NSArray *accountsArray = [store accountsWithAccountType:AccountType];  
   for (ACAccount *myaccount in accountsArray) {  
     if([myaccount.username.lowercaseString isEqualToString:aStrUserName.lowercaseString])  
     {  
       selAccount = myaccount;  
       break;  
     }  
   }  
   return selAccount;  
 }  

Thursday, October 29, 2015

How to add image in UINavigationBar in iPhone app

How to add image in UINavigationBar in iPhone app

 +(void)setNavigationBarAppearance{  
   [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"image name.png"] forBarMetrics:UIBarMetricsDefault];  
   [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:  
                              [UIColor whiteColor], NSForegroundColorAttributeName,  
                              [UIFont fontWithName:@"Font name" size:17.0], NSFontAttributeName,nil]];  
 }  

To set title view of UINavigationBar use below code

 viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage.png"]];  


How to disable back swipe gesture in UINavigationController on iOS
From iOS 7 Apple added a new default navigation behavior. You can swipe from the left border of the screen to go back on the navigation stack.
So, It is possible to disable this new gesture in UINavigationController.
Just add this online code and thats it.

  if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])  
     [self.navigationController.view removeGestureRecognizer:self.navigationController.interactivePopGestureRecognizer];  

OR

  if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])  
   self.navigationController.interactivePopGestureRecognizer.enabled = false;  


The edgesForExtendedLayout property, together with the extendedLayoutIncludesOpaqueBars property, determines whether or not view controllers' views underlap top and bottom bars (navigation bar, toolbar)
Extenedges- iOS
This is useful when you are using Storyboard and UINavigationBar & you want to start counting frame after UINavigationBar ends with autolayout.
so just select checkbox of Extenedges - Under top bars and thats it.