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

henrywood

Active Member
Licensed User
Longtime User
Hey !

I am trying to integrate social sharing functionality in my app through Objective C.

Could someone validate the methology - in particular the Objective C code ?

I would like to get an event in B4i when the user has completed sharing.

UPDATED: 09-05-2015: THIS VERSION DOES NOT WORK - PLEASE SEE POST #101 FOR A WORKING VERSION:
https://www.b4x.com/android/forum/t...elp-with-inline-objc.52849/page-6#post-336177

A BIG THANK YOU TO ALL WHO HELPED ME WITH THIS CODE !

Here is my code:

B4X:
'Code module

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.

End Sub


#If OBJC

- (IBAction)shareToSocialMedia:(NSString *)txt (NSString *)url: (NSString *)image
{
   //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:url];
   //UIImage *image = [UIImage imageNamed:@"roadfire-icon-square-200"];
   UIImage *image = [UIImage imageNamed:image];

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

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

   [self presentViewController:controller animated:YES completion:^{
     [self sharedone];
   }];
}

- (void)sharedone:
{
   int status = 1;
   [B4IObjectWrapper raiseEvent:self :@"onsharingdone:" :@[@((int)status)]];
   //[B4IObjectWrapper raiseEventFromDifferentThread:self :@"onsharingdone:" :@[@((int)status)]];

}

#end if

Sub onSharingDone(Status As Int)
   Log("onSharingDone: Status = " & Status)
End Sub

Sub ShareToSocialMedia(txt As String, theURL As String, imageFile As String)

   Dim NativeMe As NativeObject = Me
   NativeMe.RunMethod("shareToSocialMedia:", Array As Object(txt, theURL, imageFile))

End Sub
 
Last edited:

Pendrush

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

henrywood

Active Member
Licensed User
Longtime User
NEW CODE

Could you please try this:

B4X:
#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:
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Working fine if navbar is HIDDEN
When navbar is visible , same as before (code does not add extra height)
 
Upvote 0

henrywood

Active Member
Licensed User
Longtime User
This line:
B4X:
  extra += navBarHeight

should have been:

B4X:
  extra += navBarHeight;

Please try once more ?
 
Upvote 0

henrywood

Active Member
Licensed User
Longtime User
Could you please try this code:

B4X:
#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
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Parsing code. 0.00
Compiling code. 0.03
Compiling layouts code. 0.01
Compiling debugger engine code. 1.04
Building Xcode project 0.02
Sending data to remote compiler. Error
B4i line: 1
Sub Process_Globals
use of undeclared identifier 'UIApplicationsharedApplication'

Out: Build settings from command line:
ARCHS = armv7
CODE_SIGN_IDENTITY = iPhone
CONFIGURATION_BUILD_DIR = /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload
OTHER_CODE_SIGN_FLAGS = --keychain YYYYY
PRODUCT_NAME = Share Test
PROVISIONING_PROFILE = a8c9b708-d79e-45cd-ad11-78665897784c

=== BUILD TARGET B4iProject OF PROJECT B4iProject WITH CONFIGURATION Release ===

Check dependencies

Write auxiliary files
/bin/mkdir -p /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-non-framework-target-headers.hmap
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap
/bin/mkdir -p /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/Share\ Test.LinkFileList
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test.hmap

Create product structure
/bin/mkdir -p /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/Share\ Test.app

ProcessInfoPlistFile Payload/Share\ Test.app/Info.plist B4iProject/B4iProject-Info.plist
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
builtin-infoPlistUtility /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/B4iProject-Info.plist -genpkginfo /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/Share\ Test.app/PkgInfo -expandbuildsettings -format binary -platform iphoneos -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/Share\ Test.app/Info.plist

CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/main.o B4iProject/main.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/folders/l1/slt7vrsd5xn8w_n1khzmlq340000gn/C/org.llvm.clang/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DNS_BLOCK_ASSERTIONS=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -fvisibility=hidden -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources/armv7 -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources -F/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload -F../../Libs -MMD -MT dependencies -MF /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/main.d --serialize-diagnostics /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/main.dia -c /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/main.m -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/main.o

CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.o B4iProject/b4i_main.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/folders/l1/slt7vrsd5xn8w_n1khzmlq340000gn/C/org.llvm.clang/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DNS_BLOCK_ASSERTIONS=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -fvisibility=hidden -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources/armv7 -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources -F/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload -F../../Libs -MMD -MT dependencies -MF /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.d --serialize-diagnostics /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.dia -c /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_main.m -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.o

CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.o B4iProject/b4i_modshare.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/folders/l1/slt7vrsd5xn8w_n1khzmlq340000gn/C/org.llvm.clang/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DNS_BLOCK_ASSERTIONS=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -fvisibility=hidden -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources/armv7 -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources -F/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload -F../../Libs -MMD -MT dependencies -MF /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.d --serialize-diagnostics /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.dia -c /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.o
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:65:9: error: use of undeclared identifier 'UIApplicationsharedApplication'
[UIApplicationsharedApplication].statusBarHidden ? 0 : (
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:66:11: error: use of undeclared identifier 'UIApplicationsharedApplication'
[UIApplicationsharedApplication].statusBarFrame.size.height > 100 ?
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:67:11: error: use of undeclared identifier 'UIApplicationsharedApplication'
[UIApplicationsharedApplication].statusBarFrame.size.width :
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:68:11: error: use of undeclared identifier 'UIApplicationsharedApplication'
[UIApplicationsharedApplication].statusBarFrame.size.height
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:84:30: error: use of undeclared identifier 'text'; did you mean 'txt'?
initWithActivityItems:mad:[text, url, image]
^~~~
txt
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:62:39: note: 'txt' declared here
- (void)share2SocialMedia:(NSString *)txt :(NSString *)theurl :(NSString *)theimg :(UIView *)SBview
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:114:6: error: unknown type name 'AppDelegate'; did you mean 'B4IAppDelegate'?
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
^~~~~~~~~~~
B4IAppDelegate
In file included from /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:2:
In file included from /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.h:1:
../../Libs/iCore.h:334:12: note: 'B4IAppDelegate' declared here
@interface B4IAppDelegate : UIResponder <UIApplicationDelegate>
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:114:34: error: use of undeclared identifier 'AppDelegate'; did you mean 'appDelegate'?
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
^~~~~~~~~~~
appDelegate
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:114:19: note: 'appDelegate' declared here
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:114:46: error: expected expression
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:114:48: error: missing '[' at start of message send expression
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
^
[
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:114:91: error: expected ']'
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:114:47: note: to match this '['
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:115:41: error: property 'navController' not found on object of type 'B4IAppDelegate *'
CGFloat navBarHeight = appDelegate.navController.navigationBar.frame.size.height;
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:119:34: error: expected expression
extra += STATUS_BAR_HEIGHT;
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:122:22: error: property 'navController' not found on object of type 'B4IAppDelegate *'
if (appDelegate.navController.navigationBarHidden == NO)
^
13 errors generated.

CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/LS_home.o B4iProject/LS_home.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/folders/l1/slt7vrsd5xn8w_n1khzmlq340000gn/C/org.llvm.clang/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DNS_BLOCK_ASSERTIONS=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -fvisibility=hidden -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources/armv7 -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources -F/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload -F../../Libs -MMD -MT dependencies -MF /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/LS_home.d --serialize-diagnostics /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/LS_home.dia -c /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/LS_home.m -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/LS_home.o


Error: ** BUILD FAILED **


The following build commands failed:
CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.o B4iProject/b4i_modshare.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
 
Upvote 0

henrywood

Active Member
Licensed User
Longtime User
What about:

B4X:
#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:
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Parsing code. 0.03
Compiling code. 0.12
Compiling layouts code. 0.04
Compiling debugger engine code. 1.08
Building Xcode project 0.10
Sending data to remote compiler. Error
B4i line: 1
Sub Process_Globals
use of undeclared identifier 'UIApplicationsharedApplication'

Out: Build settings from command line:
ARCHS = armv7
CODE_SIGN_IDENTITY = iPhone
CONFIGURATION_BUILD_DIR = /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload
OTHER_CODE_SIGN_FLAGS = --keychain YYYYY
PRODUCT_NAME = Share Test
PROVISIONING_PROFILE = a8c9b708-d79e-45cd-ad11-78665897784c

=== BUILD TARGET B4iProject OF PROJECT B4iProject WITH CONFIGURATION Release ===

Check dependencies

Write auxiliary files
/bin/mkdir -p /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-non-framework-target-headers.hmap
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap
/bin/mkdir -p /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/Share\ Test.LinkFileList
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap
write-file /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test.hmap

Create product structure
/bin/mkdir -p /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/Share\ Test.app

ProcessInfoPlistFile Payload/Share\ Test.app/Info.plist B4iProject/B4iProject-Info.plist
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
builtin-infoPlistUtility /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/B4iProject-Info.plist -genpkginfo /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/Share\ Test.app/PkgInfo -expandbuildsettings -format binary -platform iphoneos -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/Share\ Test.app/Info.plist

CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/main.o B4iProject/main.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/folders/l1/slt7vrsd5xn8w_n1khzmlq340000gn/C/org.llvm.clang/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DNS_BLOCK_ASSERTIONS=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -fvisibility=hidden -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources/armv7 -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources -F/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload -F../../Libs -MMD -MT dependencies -MF /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/main.d --serialize-diagnostics /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/main.dia -c /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/main.m -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/main.o

CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.o B4iProject/b4i_main.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/folders/l1/slt7vrsd5xn8w_n1khzmlq340000gn/C/org.llvm.clang/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DNS_BLOCK_ASSERTIONS=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -fvisibility=hidden -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources/armv7 -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources -F/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload -F../../Libs -MMD -MT dependencies -MF /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.d --serialize-diagnostics /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.dia -c /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_main.m -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_main.o

CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.o B4iProject/b4i_modshare.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/folders/l1/slt7vrsd5xn8w_n1khzmlq340000gn/C/org.llvm.clang/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DNS_BLOCK_ASSERTIONS=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -fvisibility=hidden -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources/armv7 -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources -F/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload -F../../Libs -MMD -MT dependencies -MF /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.d --serialize-diagnostics /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.dia -c /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.o
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:65:9: error: use of undeclared identifier 'UIApplicationsharedApplication'
[UIApplicationsharedApplication].statusBarHidden ? 0 : (
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:66:11: error: use of undeclared identifier 'UIApplicationsharedApplication'
[UIApplicationsharedApplication].statusBarFrame.size.height > 100 ?
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:67:11: error: use of undeclared identifier 'UIApplicationsharedApplication'
[UIApplicationsharedApplication].statusBarFrame.size.width :
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:68:11: error: use of undeclared identifier 'UIApplicationsharedApplication'
[UIApplicationsharedApplication].statusBarFrame.size.height
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:115:41: error: property 'navController' not found on object of type 'B4IAppDelegate *'
CGFloat navBarHeight = appDelegate.navController.navigationBar.frame.size.height;
^
/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/b4i_modshare.m:122:22: error: property 'navController' not found on object of type 'B4IAppDelegate *'
if (appDelegate.navController.navigationBarHidden == NO)
^
6 errors generated.

CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/LS_home.o B4iProject/LS_home.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/folders/l1/slt7vrsd5xn8w_n1khzmlq340000gn/C/org.llvm.clang/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DNS_BLOCK_ASSERTIONS=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -fvisibility=hidden -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-generated-files.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-own-target-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-all-target-headers.hmap -iquote /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Share\ Test-project-headers.hmap -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources/armv7 -I/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/DerivedSources -F/Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/Payload -F../../Libs -MMD -MT dependencies -MF /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/LS_home.d --serialize-diagnostics /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/LS_home.dia -c /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/B4iProject/LS_home.m -o /Users/XXXXX/b4iBuild/UploadedProjects/YYYYY/build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/LS_home.o


Error: ** BUILD FAILED **


The following build commands failed:
CompileC build/B4iProject.build/Release-iphoneos/B4iProject.build/Objects-normal/armv7/b4i_modshare.o B4iProject/b4i_modshare.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

henrywood

Active Member
Licensed User
Longtime User
Last try:

B4X:
#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
 
Upvote 0

henrywood

Active Member
Licensed User
Longtime User
The very last try:

B4X:
'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:
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
The very last try:

B4X:
'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...



Error

Application_Start
Application_Active
Error occurred on line: 110 (modshare)
[<NSConcreteValue 0x17d5b350> valueForUndefinedKey:]: this class is not key value coding-compliant for the key size.
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
Foundation <redacted> + 262
Foundation <redacted> + 202
Share Test -[B4INativeObject GetField:] + 124
Share Test -[b4i_modshare _sharetosocialmedia:::::] + 1594
Share Test -[b4i_main _cmdsharelocalimage_click] + 1328
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
Share Test +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1928
Share Test -[B4IShell runMethod:] + 496
Share Test -[B4IShell raiseEventImpl:method:args::] + 1846
Share Test -[B4IShellBI raiseEvent:event:params:] + 1316
Share Test __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib <redacted> + 1322
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1512
CoreFoundation CFRunLoopRunSpecific + 476
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 136
UIKit UIApplicationMain + 1440
Share Test main + 108
libdyld.dylib <redacted> + 2
)
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Last try:

B4X:
#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

This code working as expected with and without navbar.
 
Upvote 0

henrywood

Active Member
Licensed User
Longtime User
ok, but I would just prefer not to hardcode that value of 44 for the navBarHeight, but thanks for the feedback...
 
Upvote 0

henrywood

Active Member
Licensed User
Longtime User
Maybe this will work:

B4X:
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:
Upvote 0
Top