Powered By Blogger
Showing posts with label Facebook API. Show all posts
Showing posts with label Facebook API. Show all posts

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

Saturday, March 31, 2012

iPhone SDKs and APIs

Hi Friends,
I'm going to list out some useful APIs/ SDKs for iOS Application Development environment. So, please make your closure look here.


1) Foursquare Real Time API
The foursquare APIv2 gives you access to all of the data used by the foursquare mobile applications, and, in some cases, even more.
Link : https://developer.foursquare.com/docs/realtime.html

2) Verizon Network APIs
Integrate into your mobile application Verizon's rich array of network functions.
LINK : http://developer.verizon.com/content/vdc/en/verizon-tools-apis/verizon_apis/network-api.html

3) Instagram API
Use these REST and Search APIs to utilize Instagram photos within your app.
Link  : http://instagram.com/developer/

4) Twitter :
 REST API, real-time search index, and streaming API to get tweets in real-time.
Link : https://dev.twitter.com/

5) Dropbox
Dropbox is a free service that lets you bring all your photos, docs, and videos anywhere, and share them easily.
Link : http://www.dropbox.com/developers/releases

6) Bump
Users "bump" their phones to share data within an app.
Link : http://bu.mp/api

7) iPhone ARKit
iPhone ARKit is an Objective-C augmented reality kit for iPhone.
Link : https://github.com/zac/iphonearkit/

8) Core AR
Core AR AR(Augmented reality) framework for iOS, based on a visual code like ARToolKit.
Link : https://github.com/sonsongithub/CoreAR

9) Viewdle Face Recognition
Viewdle's face recognition products to instantly tag friends & share your photos and videos as you create them, from your mobile phone, desktop, or browser!
Link : http://www.viewdle.com/products/ios/index.html

10) PDF Reader
Basic PDF Reader/Viewer for iOS.
Link : https://github.com/vfr/Reader

11) PSGoogleReader
Google Reader class for iOS (iPhone / iPad / iPod Touch).
Link : https://github.com/perspecdev/PSGoogleReader

12) Kal Calendar
A calendar component for the iPhone (the UI is designed to match MobileCal).

Link : https://github.com/klazuka/Kal

13) TouchRSS
TouchRSS is a general purpose RSS and Atom reading framework.
Link : https://github.com/TouchCode/TouchRSS

14) TouchJSON
TouchJSON is an Objective-C based parser and generator for JSON encoded data. TouchJSON compiles for Mac OS X and iOS devices (currently iPhone, iPad and iPod Touch).
Link : https://github.com/TouchCode/TouchJSON

15) ASIHTTPRequest
ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier. It is written in Objective-C and works in both Mac OS X and iPhone applications.
Link : http://allseeing-i.com/ASIHTTPRequest/

16) Mobile App Tracking
Track all your mobile web and app-2-app installs with one SDK.
Link : https://platform.mobileapptracking.com/#!/advertiser

17) ZipWeather
ZipWeather allows you to look up weather conditions by ZIP Code.
Link : http://www.appsamuck.com/day15.html

18) PhoneGap
PhoneGap is an HTML5 app platform that allows you to author native applications with web technologies and get access to APIs and app stores.
Link : http://www.phonegap.com/docs

19) Route-Me
Route-Me is an open source map library that runs natively on iOS. It's designed to look and feel much like the inbuilt iOS map library, but it's entirely open, and works with any map source.
Link : https://github.com/route-me/route-me

20)MobClix
Mobclix manages everything for you – bringing the best ads to one platform, and handling all the details so you can stay focused on building great apps.
Link : http://www.mobclix.com/developer

If any one has query then place you it over here.

Thanks and Regards,
Nilesh Prajapati