Powered By Blogger

Thursday, December 18, 2014

Steps to regenerate libzbar library for 64-bit architecture support.

Hi everyone,
After a long time, I'm back to share some useful things with you. In now a days, I'm busy to make my application 64-bit architecture devices support as per apple's guide line which must be followed before 1st February 2015. So, I have started to make third party libraries compatible to 64-bit architecture. For that, I choose libZbar and steps are as defined below : (iPhone 6 & 6 Plus support)
Step 1 : Download the source code (you must have Mercurial for mac):
Step 2 : Open Terminal and run following commands
        b. To Enter zbar directory command : cd zbar
        c. To checkout command : hg checkout iPhoneSDK-1.3.1
        d. To open project use this command : open iphone/zbar.xcodeproj
Step 3 : In the xcode project edit the "libzbar" scheme and select Release in Build configuration
Step 4 : Go to Build Settings set following Architectures
         a. Architectures - > Standard architectures(armv7,armv72,arm64)
         b. Valid Architectures -> arm64,armv7 armv7s
Step 5 : Compile libzbar for device AND for simulator, here the configuration:
Step 6 : Find the compiled libzbar.a and go in the folder using Teminal.app,
In My Case : /Users/Nell/Library/Developer/Xcode/DerivedData/zbar-gyozyrpbqzvslmfoadhqkwskcesd/Build/Products
Step 7 : In this folder, you should have two sub folders namely "Release-iphoneos" and "Release-iphonesimulator".
Step 8 : using xcode command line tools build your universal lib:
      lipo -create Release-iphoneos/libzbar.a Release-iphonesimulator/libzbar.a -o libzbar.a
Now you can use the libzbar.a created, both in device and simulator.

Regards ,
Nilesh M. Prajapati

Wednesday, May 14, 2014

How to print log for debug mode only in iOS application?

Hi,
Everyone,

Sometimes, we wish to print console in our code for DEBUG mode only. Somehow, We also forget to remove that line from our code too at the time of execution of our product. 


So, I found better solution which helps you to overcome this situation. Please keep below code in your common file and use it anywhere in your code or put it in .pch file of your project.



/******* Start Here ********/

#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif

// ALog always displays output regardless of the DEBUG setting

#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

/******* End Here ********/


**** For Example : 

NSString *str = @"https://www.apple.com"
DLog(@"%@",str);

Console : https://www.apple.com



Regards,
Nilesh M. Prajapati

Wednesday, March 26, 2014

how to store event in native calendar of iPhone with EventKit?

Hi,
Here, I'm going to share some lines of code by which you can add an event to native calendar of an iPhone/iPad/iPod touch.  So, please prefer below code to make this functionality visible to your project.

========================================================================

Step 1: Import these framework into your project.
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>

Step 2: Now add below code to your working viewcontroller class. But before doing this make sure that you declare some necessary variables.

-(IBAction)addEventToCalendar:(id)sender
{
    if (!self.defaultCalendar)
    {
        self.eventStore = [[EKEventStore alloc]init];
        self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
    }
    // save to iphone calendar
    if([self.eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) // >= iOS 6.0
    {
        // iOS 6 and later
        // This line asks user's permission to access his calendar
        [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
         {
             if (granted) // user user is ok with it
             {
                 [self openCalendarEditViewController];
             }
         }
         else // if he does not allow
         {
             [self performSelectorOnMainThread:@selector(callAccessAlert) withObject:nil waitUntilDone:YES];
             return;
         }
         
         }];
    }
    else // < iOS 6.0
    {
        [self openCalendarEditViewController];
    }
}

-(void)openCalendarEditViewController
{
    NSString *address = @“”; // Address of place where the event will be hold
    NSString *businessUrl = @“”; //Url which you want to add with calendar event
    
    NSDate *startdate; //start date and time of event
    NSDate *enddate = //end date and time of event
    NSString *strNotes; //Add notes which you want to share in with Calendar event
    
    EKEventEditViewController  *addController = [[EKEventEditViewController alloc] init];
    // set the addController's event store to the current event store.
    EKEvent *event = [EKEvent eventWithEventStore:self.eventStore];
    event.title = @“”;//title of an event should be unique to display appointments separately
    event.notes = strNotes;
    event.location = address;
    event.URL = [NSURL URLWithString:businessUrl];
    
    event.startDate = startdate;
    event.endDate = enddate;//[startdate dateByAddingTimeInterval:duration];
    
    NSDate *alarmDate = [startdate dateByAddingTimeInterval:-3600];
    NSArray *arrAlarm = [NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:alarmDate]];
    event.alarms= arrAlarm;
    
    [event setCalendar:self.defaultCalendar];
    
    addController.event = event;
    addController.eventStore = self.eventStore;
    addController.modalPresentationStyle = UIModalPresentationPageSheet;
    addController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    addController.editViewDelegate = self;
    addController.navigationBar.tintColor=[UIColor colorWithRed:0.976 green:0.612 blue:0.067 alpha:1];
    // present EventsAddViewController as a modal view controller
    [self presentModalViewController:addController animated:YES];
}

- (void)requestAccessToEntityType:(EKEntityType)entityType completion:(EKEventStoreRequestAccessCompletionHandler)completion
{
}

// Overriding EKEventEditViewDelegate method to update event store according to user actions.
- (void)eventEditViewController:(EKEventEditViewController *)controller
          didCompleteWithAction:(EKEventEditViewAction)action {
    NSError *error = nil;
    EKEvent *thisEvent = controller.event;
    switch (action) {
        case EKEventEditViewActionCanceled:
            // Edit action canceled, do nothing.
            break;
        case EKEventEditViewActionSaved:
            // When user hit "Done" button, save the newly created event to the event store,
            // and reload table view.
            // If the new event is being added to the default calendar, then update its
            // eventsList.
        {
            NSError *err = nil;
            BOOL isSuceess=[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];
        }
            break;
        case EKEventEditViewActionDeleted:
            // When deleting an event, remove the event from the event store,
            // and reload table view.
            // If deleting an event from the currenly default calendar, then update its
            // eventsList.
            [controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
            break;
        default:
            break;
    }
    // Dismiss the modal view controller
    [controller dismissModalViewControllerAnimated:YES];
}

// Set the calendar edited by EKEventEditViewController to our chosen calendar - the default calendar.
- (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller {
    EKCalendar *calendarForEdit = self.defaultCalendar;
    return calendarForEdit;

}

------------------

Regards,
Nilesh M. Prajapati


Monday, March 10, 2014

UICollectionView with dynamic image height

Hi,
Dear readers,

I had successfully used UICollectionView with dynamic heights of images which fetches data from NSURL string. iOS 6.0 and later versions can use "UICollectionView" to make a model like "Water Flow" or "Pinterest Layout".

Please see below steps to have it in your application.


=======================================================================

*** STEP 1 : 
A. Include these two files into your project source directory.
     1.) " CHTCollectionViewWaterfallLayout.h"
     2.) " CHTCollectionViewWaterfallLayout.m"
B. You can download these files from CHTCollectionViewWaterfallLayout .
C. Import "ImageIO.framework" into project.

=======================================================================

*** STEP 2:  

A) Generate two class files “CategoryCell.h” and “CategoryCell.m” for UICollectionViewCell.


#import "FXImageView.h"
@interface CategoryCell : UICollectionViewCell

@property (nonatomic, strong) UIButton *btnPhoto;
@property (nonatomic, strong) FXImageView *photoView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIView *bottomView;


#import "CategoryCell.h"

const CGFloat kTMPhotoQuiltViewMargin = 5;

@implementation CategoryCell

@synthesize photoView = _photoView;
@synthesize titleLabel = _titleLabel;
@synthesize btnPhoto = _btnPhoto;
@synthesize bottomView = _bottomView;

#pragma mark - Accessors

- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, self.contentView.bounds.size.width, 30.0)];
_titleLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textColor = WHITE_COLOR;
        if (IS_IPAD) {
            _titleLabel.font = FONT_BOLD(14.0);
        }
        else
        {
            _titleLabel.font = FONT_BOLD(12.0);
        }
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}

- (UIView *)bottomView {
if (!_bottomView) {
_bottomView = [[UIView alloc] initWithFrame:CGRectMake(0.0, self.contentView.bounds.size.height - 30.0, self.contentView.bounds.size.width, 30.0)];
_bottomView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
_bottomView.backgroundColor = BLACK_COLOR;
        _bottomView.alpha = 0.6;
}
return _bottomView;
}

- (FXImageView *)photoView {
if (!_photoView) {
_photoView = [[FXImageView alloc] initWithFrame:self.contentView.bounds];
        _photoView.asynchronous = YES;
        _photoView.contentMode = UIViewContentModeScaleAspectFit;
_photoView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_photoView.backgroundColor = CLEAR_COLOR;
        _photoView.layer.shadowOpacity = 2.0;
        _photoView.layer.shadowColor = LIGHT_GRAY_COLOR.CGColor;
        _photoView.layer.shadowRadius = 2.0;
        _photoView.layer.shadowOffset = CGSizeMake(-0.5, 0.5);
}
return _photoView;
}

- (UIButton *)btnPhoto{
if (!_btnPhoto) {
_btnPhoto = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnPhoto.frame = self.contentView.bounds;
        _btnPhoto.contentMode = UIViewContentModeScaleAspectFill;
_btnPhoto.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_btnPhoto.backgroundColor = CLEAR_COLOR;
        _btnPhoto.layer.shadowOpacity = 5.0;
        _btnPhoto.layer.shadowColor = LIGHT_GRAY_COLOR.CGColor;
        _btnPhoto.layer.shadowRadius = 5.0;
        _btnPhoto.layer.shadowOffset = CGSizeMake(-1.0, 1.0);
}
return _btnPhoto;
}

#pragma mark - Life Cycle

#if !__has_feature(objc_arc)
- (void)dealloc {
[_photoView removeFromSuperview];
_photoView = nil;
    
    [_titleLabel removeFromSuperview];
_titleLabel = nil;
    
    [super dealloc];
}
#endif

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.photoView];
        [self.contentView addSubview:self.btnPhoto];
        [self.bottomView addSubview:self.titleLabel];
        [self.contentView addSubview:self.bottomView];
}
return self;
}

@end

========================================================================

*** STEP 3:  

#import <ImageIO/ImageIO.h>

#import "CHTCollectionViewWaterfallLayout.h"
#define CELL_WIDTH 150.0
#define CELL_IDENTIFIER @"GCCategoryCell"
#import "CategoryCell.h"

@interface CategoryViewController () <UICollectionViewDataSource, CHTCollectionViewDelegateWaterfallLayout>
{
    NSMutableArray *cellHeights;
    NSMutableArray *arrCategory;
    UICollectionView *collectionView;
    CGFloat cellWidth;
}
@property (nonatomic, strong) NSMutableArray *cellHeights;
@property (nonatomic, strong) NSMutableArray * arrCategory;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic) CGFloat cellWidth;

@implementation CategoryViewController
@synthesize cellHeights;
@synthesize arrCategory;
@synthesize collectionView;

@synthesize cellWidth;

- (void)viewDidLoad
{
       self.arrCategory = [[NSMutableArray alloc] init];

        self.cellWidth = CELL_WIDTH;    // Default if not setting runtime attribute
        CHTCollectionViewWaterfallLayout *layout = [[CHTCollectionViewWaterfallLayout alloc] init];
        layout.sectionInset = UIEdgeInsetsMake(0.0, 10, 10, 5.0);
        layout.headerHeight = 0;
        layout.footerHeight = 0;
        if (IS_IPAD) {
            layout.minimumColumnSpacing = 30;
            layout.minimumInteritemSpacing = 30;
        }
        else
        {
            layout.minimumColumnSpacing = 5;
            layout.minimumInteritemSpacing = 5;
        }
        CGRect frame;
        if (IS_IPAD) {
            frame = CGRectMake(0, lblTitle.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-36.0);
        }
        else
        {
            frame = CGRectMake(0, lblTitle.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-(Appdel.objTab.frame.size.height + 36.0));
        }
        self.collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:layout];
        self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        self.collectionView.dataSource = self;
        self.collectionView.delegate = self;
        self.collectionView.backgroundColor = [UIColor clearColor];
        [self.collectionView registerClass:[GCCategoryCell class] forCellWithReuseIdentifier:CELL_IDENTIFIER];

        [self.view addSubview:self.collectionView];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self updateLayoutForOrientation:[UIApplication sharedApplication].statusBarOrientation];
}

#pragma mark --------------------------
#pragma mark Accessors
#pragma mark --------------------------

- (NSMutableArray *)cellHeights
{
    if (!cellHeights)
    {
        cellHeights = [[NSMutableArray alloc] init];
    }
    return cellHeights;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                         duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation
                                            duration:duration];
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
        [self updateLayoutForOrientation:toInterfaceOrientation];
    }
}

- (void)updateLayoutForOrientation:(UIInterfaceOrientation)orientation
{
    CHTCollectionViewWaterfallLayout *layout = (CHTCollectionViewWaterfallLayout *)self.collectionView.collectionViewLayout;
    layout.columnCount = UIInterfaceOrientationIsPortrait(orientation) ? 2 : 3;
}

========================================================================

*** STEP 4:

// Call this method first to fill height array after you objects list
-(void)fillHeightArray
{
                for (NSMutableDictionary *dictGCCatInfo in self.arrCategory)
                {
                    NSNumber *width = [NSNumber numberWithFloat:200];
                    NSNumber *height = [NSNumber numberWithFloat:200];
                    
                    NSString *urlString = [dictGCCatInfo valueForKey:@"Photo"];
                    NSURL *imageFileURL = [NSURL URLWithString:urlString];
                    CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)imageFileURL, NULL);
                    if (imageSource) {
                        NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache, nil];
                        CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (__bridge CFDictionaryRef)options);
                        if (imageProperties) {
                            width = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
                            height = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
                            CFRelease(imageProperties);
                        }
                    }
                    CFRelease(imageSource); // Added
                    CGSize size = CGSizeMake([width floatValue], [height floatValue]);
                    [self.cellHeights addObject:[NSValue valueWithCGSize:size]];
                }
[self.collectionView reloadData];
}

#pragma mark -----------------------------
#pragma mark UICollectionViewDataSource
#pragma mark -----------------------------

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [arrCategory count];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView1 cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CategoryCell *cell = (CategoryCell *)[collectionView1 dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER
                                                                                       forIndexPath:indexPath];
    NSString *urlString = [[arrCategory objectAtIndex:indexPath.row] valueForKey:@"Photo"];
    if (urlString)
    {
        [cell.photoView setProcessedImage:nil];
        //set image
        [cell.photoView setImageWithContentsOfURL:[NSURL URLWithString:urlString]];
    }
    else
    {
        [cell.photoView setImage:[UIImage imageNamed:@"no-image.png"]];
    }
    [cell.photoView setTag:indexPath.row];
    [cell.btnPhoto setTag:indexPath.row];
    cell.titleLabel.text = [[arrCategory objectAtIndex:indexPath.row] valueForKey:@"GiftCertificateCatName"];
    [cell.btnPhoto addTarget:self action:@selector(btnCategoryClicked:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

#pragma mark ------------------------------------
#pragma mark CHTCollectionViewDelegateWaterfallLayout
#pragma mark ------------------------------------

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGSize size = [[self.cellHeights objectAtIndex:indexPath.row] CGSizeValue];
    return size;
}

Hope, you will fully enjoy this post about UICollectionView.

Best Regards,
Nilesh M. Prajapati

Monday, January 27, 2014

Asynchronous image downloading with dispatch_async queue

Hi,

There's no need to implement any framework for LazyImage loading as of now. You can do it simply by writing few lines of code below.. Just take a look..


Example : 

UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc]init];
UIImageView * userImage = [[UIImageView alloc]init];

        [activity startAnimating];
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
        dispatch_async(queue, ^(void) {
            //  You may want to cache this explicitly instead of reloading every time.
            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
            UIImage* image = [[UIImage alloc] initWithData:imageData];
            dispatch_async(dispatch_get_main_queue(), ^{
                // Capture the indexPath variable, not the cell variable, and use that
               userImage.image = image;
                [activity stopAnimating];
            });
       });


Regards,
Nilesh M. Prajapati

Monday, January 13, 2014

how to share information in iPhone?

Hi,
Recently I have integrated UIActivityViewController in my one of the applications for iOS 6.0 and later versions. For iOS 5.1.1, I used default "twitter.framework".
Please check below code to share information in your application through social media.

//******* Place below code into Implementation part *********//

UIPopoverController *popup;
UIActionSheet *actionSheet;

#define HTML_STR @"" //Any html string which you want to set at the time of sending an email for iOS 5.1.1 and below iOS.

#pragma mark -------------------
#pragma mark Share Button Click event
#pragma mark -------------------

-(IBAction)btnShareClick:(id)sender
{
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
    {
        [self showActivityView]; // For iOS 6.0 & later ....
    }
    else
    {
        [self showActionSheet]; // For iOS 5.1.1 & below ....
    }
}

#pragma mark -------------------
#pragma mark UIActivityViewController Delegate methods
#pragma mark -------------------

-(void)showActivityView // For iOS 6.0 & later ....
{
    NSMutableDictionary *dictInfo = [array objectAtIndex:index];
   
    //-- set up the data objects
    NSString *Title = [NSString stringWithFormat:@"Promotion Title : %@\n",[dictInfo valueForKey:@"Title"]];
    NSString *fullAddress = [NSString stringWithFormat:@"%@, %@",[dictInfo valueForKey:@"City"],[dictInfo valueForKey:@"StateName"]];
   NSString *validDate = [NSString stringWithFormat:@"Date : %@ To %@ \n",[dictInfo valueForKey:@"strStartDate"],[dictInfo valueForKey:@"strEndDate"]];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.xyz.com/%@",[dictInfo valueForKey:@"url"]]];
   
    UIImage *image = [UIImage imageNamed:@"title.png"];
    NSArray *activityItems = [NSArray arrayWithObjects:Title,
                              fullAddress,
                              validDate,
                              url,
                              image,nil];
   
    //-- initialising the activity view controller
    UIActivityViewController *activityView = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
    //-- define the activity view completion handler
    activityView.completionHandler = ^(NSString *activityType, BOOL completed)
    {
        NSLog(@"Activity Type selected: %@", activityType);
        if (completed)
        {
            NSLog(@"Selected activity was performed.");
        }
        else
        {
            if (activityType == NULL) {
                NSLog(@"User dismissed the view controller without making a selection.");
            }
            else {
                NSLog(@"Activity was not performed.");
            }
        }
      }
    };
   
    //-- define activity to be excluded (if any)
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
        activityView.excludedActivityTypes = [NSArray arrayWithObjects:UIActivityTypeAddToReadingList,UIActivityTypeAirDrop,nil];
    }
    else
    {
        activityView.excludedActivityTypes = [NSArray arrayWithObjects:UIActivityTypeSaveToCameraRoll,nil];
    }
   
    if (IS_IPAD)
    {
        if (self.popup) {
            [self.popup dismissPopoverAnimated:NO];
            popup = nil;
        }
        self.popup = [[UIPopoverController alloc] initWithContentViewController:activityView];
        //UIBarButtonItem *barBtn = (UIBarButtonItem *)[self.navigationItem.rightBarButtonItems objectAtIndex:3];
        self.popup.delegate = self;
        [self.popup presentPopoverFromRect:selectedButton.frame inView:selectedButton.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    else
    {
        //-- show the activity view controller
        [self presentViewController:activityView
                           animated:YES completion:^{
                               Appdel.objTab.hidden=YES;
                           }];
    }
}

#pragma mark ------------------------------
#pragma mark UIPopoverController delegate method
#pragma mark ------------------------------

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    if (self.popup) {
        [self.popup dismissPopoverAnimated:NO];
        popup = nil;
    }
}
#pragma mark ------------------------------
#pragma mark UIActionSheet delegate method
#pragma mark ------------------------------

-(void)showActionSheet // For iOS 5.1.1 & below
{
    if (actionSheet) {
        [actionSheet dismissWithClickedButtonIndex:3 animated:YES];
        actionSheet = nil;
    }
    actionSheet = [[UIActionSheet alloc]initWithTitle:@"Share with"
                                             delegate:self
                                    cancelButtonTitle:nil
                               destructiveButtonTitle:nil
                                    otherButtonTitles:@"Email",@"Facebook",@"Twitter",@"Cancel",nil];
    if (IS_IPAD)
    {
        [actionSheet showFromRect:selectedButton.frame inView:selectedButton.superview animated:YES];
    }
    else
    {
        [actionSheet showInView:self.view];
    }
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex // For iOS 5.1.1 & below
{
    switch (buttonIndex)
    {
        case 0:
            NSLog(@"Email");
        {
                [self openMailComposer];
        }
            break;
        case 1:
            NSLog(@"Facebook");
        {
            [Appdel.HUD show:YES];
            [self performSelector:@selector(dofacebookLogin) withObject:nil afterDelay:0.5];
        }
            break;
        case 2:
            NSLog(@"Twitter");
        {
                [self sendTwitToYourAccout];
        }
            break;
        case 3:
            NSLog(@"Cancel");
            break;
        default:
            break;
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet1 didDismissWithButtonIndex:(NSInteger)buttonIndex // For iOS 5.1.1 & below
{
    if (actionSheet) {
        [actionSheet dismissWithClickedButtonIndex:3 animated:YES];
        actionSheet = nil;
    }
}

#pragma mark ------------------------------
#pragma mark MFMailComposeViewController delegate method
#pragma mark ------------------------------


-(void)openMailComposer // For iOS 5.1.1 & below
{
    NSMutableDictionary *dictInfo = [array objectAtIndex:index];
  
    NSString *Title = [NSString stringWithFormat:@"Title : %@</br></br>",[dictInfo valueForKey:@"Title"]];
    NSString *fullAddress = [NSString stringWithFormat:@"%@, %@",[dictInfo valueForKey:@"City"],[dictInfo valueForKey:@"State"]];
    NSString *validDate = [NSString stringWithFormat:@"Date : %@ To %@ </br></br>",[dictInfo valueForKey:@"strStartDate"],[dictInfo valueForKey:@"strEndDate"]];
  
    NSString *strUrl = [NSString stringWithFormat:@"http://www.xyz.com/%@",[dictInfo valueForKey:@"url_name"]];
    NSString *combinedString = [NSString stringWithFormat:@"%@ %@ %@ %@",Title,fullAddress,validDate,strUrl];
    NSString *string = [NSString stringWithFormat:HTML_STR,combinedString,strUrl,[dictInfo valueForKey:@"ImageUrl"]];
  
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Send Mail"];
  
    NSArray *toRecipients = [NSArray arrayWithObject:@""];
    [picker setToRecipients:toRecipients];
  
    NSString *emailBody = [NSString stringWithFormat:@"%@",string];
    [picker setMessageBody:emailBody isHTML:YES];
      
    picker.navigationBar.tintColor=[UIColor colorWithRed:0.976 green:0.612 blue:0.067 alpha:1];
    [self presentModalViewController:picker animated:YES];
    picker = nil;
    toRecipients = nil;
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [controller dismissModalViewControllerAnimated:NO];
}

#pragma mark ------------------------------
#pragma mark TWTweetComposeViewController delegate method
#pragma mark ------------------------------

-(void)sendTwitToYourAccout// For iOS 5.1.1 & below
{
    if ([TWTweetComposeViewController canSendTweet])
    {
        NSMutableDictionary *dictInfo = [array objectAtIndex:index];
       
        NSString *promotionTitle = [NSString stringWithFormat:@"Title : %@",[dictInfo valueForKey:@"Title"]];
        NSString *validDate = [NSString stringWithFormat:@"Date : %@ To %@",[dictInfo valueForKey:@"strStartDate"],[dictInfo valueForKey:@"strEndDate"]];
        NSString *strUrl = [NSString stringWithFormat:@"http://www.xyz.com/%@",[dictInfo valueForKey:@"url_name"]];
       
        // Initialize Tweet Compose View Controller
        TWTweetComposeViewController *vc = [[TWTweetComposeViewController alloc] init];
        // Settin The Initial Text
        [vc setInitialText:[NSString stringWithFormat:@"%@\n %@",Title,validDate]];
       
        // Adding an Image
        UIImage *image = [UIImage imageNamed:@"title.png"];
        [vc addImage:image];
       
        // Adding a URL
        NSURL *url = [NSURL URLWithString:strUrl];
        [vc addURL:url];
       
        // Setting a Completing Handler
        [vc setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
            [self dismissModalViewControllerAnimated:YES];
        }];
       
        // Display Tweet Compose View Controller Modally
        [self presentViewController:vc animated:YES completion:nil];
    }
    else
    {
        // Show Alert View When The Application Cannot Send Tweets
        NSString *message = @"The application cannot send a tweet at the moment. This is because it cannot reach Twitter or you don't have a Twitter account associated with this device.";
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Warning !" message:message delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [alertView show];
    }
}

#pragma mark ------------------------------
#pragma mark FacebookSDK delegate method
#pragma mark ------------------------------

-(void) dofacebookLogin // For iOS 5.1.1 & below
{
    [SCFacebook loginCallBack:^(BOOL success, id result) {
        if (success) {
            [self sendFeedTofacebook];
        }
        else
        {
            Alert(@"Warning !", result);
        }
    }];
}

- (void)sendFeedTofacebook // For iOS 5.1.1 & below
{
        NSMutableDictionary *dictPromotionInfo = [array objectAtIndex:index];
        NSString *Title = [NSString stringWithFormat:@"Title : %@\n",[dictInfo valueForKey:@"Title"]];
        UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[dictInfo valueForKey:@"Image"]]]];
      
        NSString *validDate = [NSString stringWithFormat:@"Date : %@ To %@ \n",[dictInfo valueForKey:@"strStartDate"],[dictInfo valueForKey:@"strEndDate"]];

        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.xyz.com/%@",[dictInfo valueForKey:@"url_name"]]];
      
        [SCFacebook feedPostWithPhoto:image caption:[NSString stringWithFormat:@"%@ %@ %@ %@",Title,validDate,url] callBack:^(BOOL success, id result)
         {
             if (success) {
                 Alert(@"Info !", @"Your feed has been posted successfully over Facebook.");
             }
             else
             {
                 Alert(@"Warning !", result);
             }
         }];
}


Thanks & Regards,
-----------------------------
Nilesh M. Prajapati