Developer Area

Show
Ignore:
Timestamp:
09/13/11 11:09:35 (3 years ago)
Author:
henri
Message:

Added sharing actions

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • apps/iphone/superbook/trunk/Classes/NaptrViewController.m

    r886 r896  
    3535#import "WebUrlViewController.h" 
    3636#import "RecordNaptr+HAAdditions.h" 
     37#import "SHK.h" 
    3738 
    3839static UIFont *headerFont; 
     
    4142static CGFloat naptrCellRowLineHeight; 
    4243static CGSize maximumLabelSize; 
     44 
     45enum ActionSheets_enum { 
     46    ActionSheet_Action, 
     47    ActionSheet_Call, 
     48    ActionSheet_Share 
     49}; 
    4350 
    4451@interface NaptrViewController (PrivateMethods) 
     
    5865@synthesize loadingAIButton; 
    5966@synthesize logoImage; 
    60 @synthesize storeContactButton; 
     67@synthesize actionContactButton; 
    6168@synthesize abId; 
    6269 
     
    98105        self.loadingAIButton = [[[UIBarButtonItem alloc] initWithCustomView:self.loadingAIView] autorelease]; 
    99106         
    100         self.storeContactButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave  
     107        self.actionContactButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction  
    101108                                                                                                                                                        target:self  
    102                                                                                                                                                         action:@selector(saveContact:)] autorelease]; 
     109                                                                                                                                                        action:@selector(domainAction:)] autorelease]; 
    103110        self.logoImage = nil; 
    104111     
     
    186193                [self.loadingAIView stopAnimating]; 
    187194        [self performSelector:@selector(stopLoading) withObject:nil afterDelay:0.1]; 
    188                 self.navigationItem.rightBarButtonItem = self.storeContactButton; 
     195                self.navigationItem.rightBarButtonItem = self.actionContactButton; 
    189196        if (! self.theDomain.isCached) { 
    190197            // Cache the domain data if it's new data 
     
    824831                                                                                                   destructiveButtonTitle:nil 
    825832                                                                                                                otherButtonTitles:nil]; 
     833        actionSheet.tag = ActionSheet_Call; 
    826834                callButtonIndex = [actionSheet addButtonWithTitle:NSLocalizedString(@"Call this number", @"Call this number")]; 
    827835                smsButtonIndex = [actionSheet addButtonWithTitle:NSLocalizedString(@"Send an SMS Message", @"Send an SMS Message")]; 
     
    846854                return; 
    847855        } 
    848         NSURL *naptrUrl; 
    849         NSString *uri = [actionSheet title]; 
    850     if (buttonIndex == callButtonIndex) { 
    851                 naptrUrl = [NSURL URLWithString:[uri stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]; 
    852                 [[UIApplication sharedApplication] openURL:naptrUrl]; 
    853         } else if (buttonIndex == smsButtonIndex) { 
    854                 NSRange telPrefixRange = [uri rangeOfString:@"tel:"]; 
    855                 naptrUrl = [NSURL URLWithString:[uri stringByReplacingCharactersInRange:telPrefixRange withString:@"sms:"]]; 
    856                 [[UIApplication sharedApplication] openURL:naptrUrl]; 
     856    if (actionSheet.tag == ActionSheet_Call) { 
     857        NSURL *naptrUrl; 
     858        NSString *uri = [actionSheet title]; 
     859        if (buttonIndex == callButtonIndex) { 
     860            naptrUrl = [NSURL URLWithString:[uri stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]; 
     861            [[UIApplication sharedApplication] openURL:naptrUrl]; 
     862        } else if (buttonIndex == smsButtonIndex) { 
     863            NSRange telPrefixRange = [uri rangeOfString:@"tel:"]; 
     864            naptrUrl = [NSURL URLWithString:[uri stringByReplacingCharactersInRange:telPrefixRange withString:@"sms:"]]; 
     865            [[UIApplication sharedApplication] openURL:naptrUrl]; 
     866        } 
     867    } else if (actionSheet.tag == ActionSheet_Action) { 
     868        if (buttonIndex == 0) { // Save 
     869            [self saveContact:nil]; 
     870        } else if (buttonIndex == 1) { // Share 
     871            [self shareContact:nil]; 
     872        } 
    857873    } 
    858874        return; 
    859875} 
    860876 
    861 #pragma mark ------ Methods to save a contact 
     877#pragma mark ------ Action methods 
     878 
     879- (IBAction)domainAction:(id)sender { 
     880    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
     881                                                             delegate:self 
     882                                                    cancelButtonTitle:nil 
     883                                               destructiveButtonTitle:nil 
     884                                                    otherButtonTitles:nil]; 
     885    actionSheet.tag = ActionSheet_Action; 
     886    [actionSheet addButtonWithTitle:NSLocalizedString(@"Save to Address Book", @"Save")]; 
     887    [actionSheet addButtonWithTitle:NSLocalizedString(@"Share this", @"Share")]; 
     888    actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:NSLocalizedString(@"Cancel", @"Cancel")]; 
     889    [actionSheet showInView:self.view]; 
     890    [actionSheet release]; 
     891} 
    862892 
    863893- (IBAction)saveContact:(id)sender { 
     
    874904                [self showError:err]; 
    875905        } 
     906} 
     907 
     908- (IBAction)shareContact:(id)sender { 
     909    // Create the item to share (in this example, a url) 
     910        NSURL *url = [NSURL URLWithString:[@"http://" stringByAppendingString:self.theDomain.telName]]; 
     911    NSString *urlString = [url.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
     912    NSString *sharingString = [NSString stringWithFormat:NSLocalizedString(@"I just checked out %@ on Superbook", @"sharing string"), urlString]; 
     913        SHKItem *item = [SHKItem text:sharingString]; 
     914     
     915        // Get the ShareKit action sheet 
     916        SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];     
     917        // Display the action sheet 
     918    [actionSheet showInView:self.view]; 
    876919} 
    877920 
Telnic
Search This Site
Partners
Neustar
ICANN
Main site | WHOIS | Sell .tel | FAQ | Archived Site | About Telnic | Contact Us