iOS Question Share to social media functionality - Help with inline objC

Discussion in 'iOS Questions' started by henrywood, Apr 13, 2015.

  1. Pendrush

    Pendrush Well-Known Member Licensed User

    Great job mate.
    Just got tested project on multiple layouts.
    Working as expected with and without NavBar, in portrait and landscape on iPhone and on iPad.
     

    Attached Files:

    Ohanian and Mark Turney like this.
  2. henrywood

    henrywood Active Member Licensed User

  3. Albi

    Albi Active Member Licensed User

    this is incredible, thank's muchly to everyone who made it!
     
  4. Albi

    Albi Active Member Licensed User

    i have one question about this now - when emailing picture using the mail composer, you have the option of choosing the file size, which doesn't happen when using this class. any idea how to change this class to give that option?

    EDIT: my mistake, it does do that! woopwoop
     
    Last edited: Jun 10, 2015
  5. Pendrush

    Pendrush Well-Known Member Licensed User

    Now we have this warning (when click on Share) in iOS 9 beta 3

    iPad error:

    iPhone error:
     
    Last edited: Jul 13, 2015
  6. henrywood

    henrywood Active Member Licensed User

    I don't have a clue as to why this happens. Also don't have iOS 9
    Maybe @Erel can help ?
     
  7. tufanv

    tufanv Expert Licensed User

    anyupdate on this issue ?
     
  8. wineos

    wineos Member Licensed User

    Did the above warning being solved?

    Thank you.
     
  9. Pendrush

    Pendrush Well-Known Member Licensed User

    In iOS 9.0.2, warning on iPad is a bit different then above warning, and still need fix :(
     
    wineos likes this.
  10. wineos

    wineos Member Licensed User

    Can I use it anyway? Will Apple accept it?

    Thank you.
     
  11. Pendrush

    Pendrush Well-Known Member Licensed User

    I have used in my (approved) apps without any problem so far.
     
    Erel and wineos like this.
  12. wineos

    wineos Member Licensed User

    Thank you Pendrush
     
  13. cloner7801

    cloner7801 Active Member Licensed User

    I am using this code :
    Code:
    Sub Process_Globals

      
    Private myPage As Page 'ignore
    End Sub

    #IF OBJC

    //- (void)share2SocialMedia:(NSString *)txt :(NSString *)theurl :(NSString *)theimg :(UIView *)SBview :(float)nbHeight
    - (void)share2SocialMedia:(NSString *)txt :(NSString *)theurl :(NSString *)theimg :(UIView *)SBview :(UINavigationBar *)nb
    {

       CGFloat STATUS_BAR_HEIGHT = (
           [UIApplication sharedApplication].statusBarHidden ? 0 : (
             [UIApplication sharedApplication].statusBarFrame.size.height > 100 ?
             [UIApplication sharedApplication].statusBarFrame.size.width :
             [UIApplication sharedApplication].statusBarFrame.size.height
           )
       );

         //NSString *text = @"How to add Facebook and Twitter sharing to an iOS app";
         NSString *text = txt;
         //NSURL *url = [NSURL URLWithString:@"http://roadfiresoftware.com/2014/02/how-to-add-facebook-and-twitter-sharing-to-an-ios-app/"];
         NSURL *url = [NSURL URLWithString:theurl];
         //UIImage *image = [UIImage imageNamed:@"roadfire-icon-square-200"];
         UIImage *image;

         if([theimg hasPrefix:@"http://"] || [theimg hasPrefix:@"https://"] ) {
           image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:theimg]]];
         } else {
         if (theimg != nil && [theimg length] > 0) {
             image = [UIImage imageNamed:theimg];
           } else {
           image = nil;
         }
       }

         UIActivityViewController *controller =
         [[UIActivityViewController alloc]
         initWithActivityItems:@[text, url, image]
         applicationActivities:nil];

         controller.excludedActivityTypes = @[UIActivityTypePostToWeibo,
         UIActivityTypePrint,
         UIActivityTypeAssignToContact,
         UIActivityTypeSaveToCameraRoll,
         UIActivityTypeAddToReadingList,
         UIActivityTypePostToFlickr,
         UIActivityTypePostToVimeo,
         UIActivityTypePostToTencentWeibo];

         [controller setCompletionHandler:^(NSString*activityType, BOOL completed) {

           // Raise the event for B4i
           if (completed) {
           [self.bi raiseEvent:nil event:@"activity_completed::" params:@[@((BOOL)completed),(activityType)]];
           } else {

             NSString *activity = @"";
           [self.bi raiseEvent:nil event:@"activity_completed::" params:@[@((BOOL)completed),(activity)]];
           }
         }];

         //if iPhone
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
         [(self._mypage).object presentViewController:controller animated:YES completion:nil];
       } else { //if iPad

           UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:controller];
         UIWindow *window = [[UIApplication sharedApplication] keyWindow];
         UIView *topView = window.rootViewController.view;
         CGFloat extra = 0;
      
         if (nb != nil) {
           extra += nb.frame.size.height;
         }
      
         if ([UIApplication sharedApplication].statusBarHidden == NO)
         {
           extra += STATUS_BAR_HEIGHT;
         }
         //[popup presentPopoverFromRect:CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/4, 0, 0)inView:topView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
         //[popup presentPopoverFromRect:CGRectMake(SBview.Left + SBview.Width/2, SBview.Top+SBview.Height,0,SBview.Height)inView:topView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
           [popup presentPopoverFromRect:CGRectMake(SBview.Left + SBview.Width/2, SBview.Top+SBview.Height+extra, 0, 0)inView:topView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
         }
    }

    #End If

    Sub activity_completed(status As Boolean, T As String)

    'If Main.DEBUG Then
    '    Utils.Log_("onSharingDone: Status = " & status & " - Type: " & T & " - Will look for callback: ShareModule_SharingCompleted in " & myPage.Title)
    'End If

      
    'If SubExists(myPage, "ShareModule_SharingCompleted", 2) = True Then
       '  CallSub3(myPage, "ShareModule_SharingCompleted", status, T)
      'End If

    End Sub

    Sub ShareToSocialMedia(p As Page, txt As String, theURL As String, imageFileOrURL As String, shareButton As View)

        
    Dim v As View = shareButton

        myPage = p
        
    Dim NativeMe As NativeObject = Me
        
    Dim NativeMe2 As NativeObject = Main.NavControl
        
    Dim NativeMe3 As NativeObject = NativeMe2.GetField("navigationBar")
        
    Dim nb As Object = NativeMe3

        
    If Main.NavControl.NavigationBarVisible Then
            NativeMe.RunMethod(
    "share2SocialMedia:::::"Array As Object(txt, theURL, imageFileOrURL, v, nb))
        
    Else
            NativeMe.RunMethod(
    "share2SocialMedia:::::"Array As Object(txt, theURL, imageFileOrURL, v, Null))
        
    End If

    End Sub
    When click on copy its copy the image , I want to copy text what should I do?
     
  14. jazzzzzzz

    jazzzzzzz Active Member Licensed User

    I have tried to run your code on my iPhone 6S with iOS 9.3.2 but only text is shared,Image is not at all sharing.
    I haven't changed any code in your project
     
    cloner7801 likes this.
  15. Descartex

    Descartex Well-Known Member Licensed User

    Hi,
    I'm trying to integrate this function to my app, but i can't make work the sample with local file.
    It raises this error:
    *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]
    And the code i'm trying to run is:
    Code:
    Dim strImagePath As String
    strImagePath = 
    File.DirDocuments & "temp.png"
    Log(strImagePath)
    modShare.ShareToSocialMedia(pg, 
    "File Shared successfully""", strImagePath, Sender)
    If I run the sample with Online Image, it runs perfectly.
    Thanks in advance.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice