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

    /b4i_modshare.m:110:29: error: interface type cannot be statically allocated
    UINavigationController navCtl = window.rootViewController.navigationController;
    ^
    /b4i_modshare.m:112:39: error: property 'statusBar' not found on object of type 'UINavigationController *'
    CGFloat statusBarHeight = navCtl.statusBar.frame.size.height;
    ^
    2 errors generated.
     
  2. henrywood

    henrywood Active Member Licensed User

    NEW CODE

    Could you please try this:

    Code:
    #IF OBJC

    - (void)share2SocialMedia:(NSString *)txt :(NSString *)theurl :(NSString *)theimg :(UIView *)SBview
    {

    #define STATUS_BAR_HEIGHT (
      [UIApplicationsharedApplication].statusBarHidden ? 0 : (
      [UIApplicationsharedApplication].statusBarFrame.size.height > 100 ?
      [UIApplicationsharedApplication].statusBarFrame.size.width :
      [UIApplicationsharedApplication].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 {
      image = [UIImage imageNamed:theimg];
      }

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

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

      [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
      // Change Rect to position Popover
         UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:controller];
         UIWindow *window = [[UIApplication sharedApplication] keyWindow];
         UIView *topView = window.rootViewController.view;
         UINavigationController *navCtl = window.rootViewController.navigationController;
         CGFloat navBarHeight = navCtl.navigationBar.frame.size.height;
         CGFloat extra = 0;

         if ([UIApplication sharedApplication].statusBarHidden == NO)
         {
              extra += STATUS_BAR_HEIGHT;
         }
         if (navCtl.navigationBarHidden == NO)
         {
              extra += navBarHeight;
         }


         //[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
     
    Last edited: May 9, 2015
  3. Pendrush

    Pendrush Well-Known Member Licensed User

    Working fine if navbar is HIDDEN
    When navbar is visible , same as before (code does not add extra height)
     
  4. henrywood

    henrywood Active Member Licensed User

    This line:
    Code:
    extra += navBarHeight
    should have been:

    Code:
    extra += navBarHeight;
    Please try once more ?
     
  5. Pendrush

    Pendrush Well-Known Member Licensed User

    its a typo, change in first try. I'm unable to compile without ;
     
  6. henrywood

    henrywood Active Member Licensed User

    Could you please try this code:

    Code:
    #IF OBJC

    - (void)share2SocialMedia:(NSString *)txt :(NSString *)theurl :(NSString *)theimg :(UIView *)SBview
    {

       #define STATUS_BAR_HEIGHT (
           [UIApplicationsharedApplication].statusBarHidden ? 0 : (
             [UIApplicationsharedApplication].statusBarFrame.size.height > 100 ?
             [UIApplicationsharedApplication].statusBarFrame.size.width :
             [UIApplicationsharedApplication].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 {
           image = [UIImage imageNamed:theimg];
         }

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

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

         [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;
         AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
         CGFloat navBarHeight = appDelegate.navController.navigationBar.frame.size.height;
         CGFloat extra = 0;

         if ([UIApplication sharedApplication].statusBarHidden == NO)
         {
           extra += STATUS_BAR_HEIGHT;
         }
       
         if (appDelegate.navController.navigationBarHidden == NO)
         {
           extra += navBarHeight;
         }

         //[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
     
  7. Pendrush

    Pendrush Well-Known Member Licensed User

     
  8. henrywood

    henrywood Active Member Licensed User

    What about:

    Code:
    #IF OBJC

    - (void)share2SocialMedia:(NSString *)txt :(NSString *)theurl :(NSString *)theimg :(UIView *)SBview
    {

       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 {
           image = [UIImage imageNamed:theimg];
         }

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

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

         [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;
         B4IAppDelegate *appDelegate = (B4IAppDelegate*)[[UIApplication sharedApplication] delegate];
         CGFloat navBarHeight = appDelegate.navController.navigationBar.frame.size.height;
         CGFloat extra = 0;

         if ([UIApplication sharedApplication].statusBarHidden == NO)
         {
           extra += STATUS_BAR_HEIGHT;
         }
      
         if (appDelegate.navController.navigationBarHidden == NO)
         {
           extra += navBarHeight;
         }

         //[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
     
    Last edited: May 9, 2015
  9. henrywood

    henrywood Active Member Licensed User

    edited the code once more - Please try again ?
     
  10. Pendrush

    Pendrush Well-Known Member Licensed User

     
  11. henrywood

    henrywood Active Member Licensed User

    Edited again ....
     
  12. Pendrush

    Pendrush Well-Known Member Licensed User

    /B4iProject/b4i_modshare.m:115:41: error: property 'navController' not found on object of type 'B4IAppDelegate *'
    CGFloat navBarHeight = appDelegate.navController.navigationBar.frame.size.height;
    ^
    /B4iProject/b4i_modshare.m:122:22: error: property 'navController' not found on object of type 'B4IAppDelegate *'
    if (appDelegate.navController.navigationBarHidden == NO)
    ^
    2 errors generated.
     
  13. henrywood

    henrywood Active Member Licensed User

    Last try:

    Code:
    #IF OBJC

    - (void)share2SocialMedia:(NSString *)txt :(NSString *)theurl :(NSString *)theimg :(UIView *)SBview :(BOOL)navBarVisible
    {

       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,
         UIActivityTypeMessage,
         UIActivityTypeMail,
         UIActivityTypePrint,
         UIActivityTypeCopyToPasteboard,
         UIActivityTypeAssignToContact,
         UIActivityTypeSaveToCameraRoll,
         UIActivityTypeAddToReadingList,
         UIActivityTypePostToFlickr,
         UIActivityTypePostToVimeo,
         UIActivityTypePostToTencentWeibo,
         UIActivityTypeAirDrop];

         [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 navBarHeight = 44;
         CGFloat extra = 0;

         if ([UIApplication sharedApplication].statusBarHidden == NO)
         {
           extra += STATUS_BAR_HEIGHT;
         }
       
         if (navBarVisible == YES)
         {
           extra += navBarHeight;
         }

         //[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 Button)
       
       
    Dim v As View = shareButton

       myPage = p
       
    Dim NativeMe As NativeObject = Me
       
       
    If Main.NavControl.NavigationBarVisible Then
         NativeMe.RunMethod(
    "share2SocialMedia:::::"Array As Object(txt, theURL, imageFileOrURL, v, True))   
       
    Else
         NativeMe.RunMethod(
    "share2SocialMedia:::::"Array As Object(txt, theURL, imageFileOrURL, v, False))
       
    End If
       
    End Sub
     
  14. henrywood

    henrywood Active Member Licensed User

    The very last try:

    Code:
    'Code module
    'Subs in this code module will be accessible from all modules.
    Sub Process_Globals
          
    Private myPage As Page
    End Sub

    #IF OBJC

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

       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,
         UIActivityTypeMessage,
         UIActivityTypeMail,
         UIActivityTypePrint,
         UIActivityTypeCopyToPasteboard,
         UIActivityTypeAssignToContact,
         UIActivityTypeSaveToCameraRoll,
         UIActivityTypeAddToReadingList,
         UIActivityTypePostToFlickr,
         UIActivityTypePostToVimeo,
         UIActivityTypePostToTencentWeibo,
         UIActivityTypeAirDrop];

         [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 navBarHeight = nbHeight;
         CGFloat extra = nbHeight;

         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 Button)

       
    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").GetField("frame").GetField("size").GetField("height")
       
    Dim h As Object = NativeMe3.AsNumber

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

    End Sub

    Could someone please try this code on IPAD ? I don't have access to an IPAD...
     
    Last edited: May 9, 2015
  15. Pendrush

    Pendrush Well-Known Member Licensed User



    Error

     
  16. Pendrush

    Pendrush Well-Known Member Licensed User

    This code working as expected with and without navbar.
     
  17. Pendrush

    Pendrush Well-Known Member Licensed User

    Share project based on previous post.
     

    Attached Files:

  18. henrywood

    henrywood Active Member Licensed User

    ok, but I would just prefer not to hardcode that value of 44 for the navBarHeight, but thanks for the feedback...
     
  19. Pendrush

    Pendrush Well-Known Member Licensed User

    Yes, that would be nice. I will try something tomorrow.
    Thank you.
     
  20. henrywood

    henrywood Active Member Licensed User

    Maybe this will work:

    Code:
    Sub Process_Globals

      
    Private myPage As Page
     
    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,
         UIActivityTypeMessage,
         UIActivityTypeMail,
         UIActivityTypePrint,
         UIActivityTypeCopyToPasteboard,
         UIActivityTypeAssignToContact,
         UIActivityTypeSaveToCameraRoll,
         UIActivityTypeAddToReadingList,
         UIActivityTypePostToFlickr,
         UIActivityTypePostToVimeo,
         UIActivityTypePostToTencentWeibo,
         UIActivityTypeAirDrop];

         [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 Button)
     
       
    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").GetField("frame").GetField("size").GetField("height")
       'Dim h As Object = NativeMe3.AsNumber
       'Dim h As Float = 44
       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
     
    Last edited: May 10, 2015
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