HaxeExtension / extension-share

Share Extension for OpenFL
Other
43 stars 12 forks source link

Share-extension doesn't works in iOS #5

Closed ispebo closed 9 years ago

ispebo commented 9 years ago

Hello Just try for the first time "extension-share". I tried for two targets: Android and iOS. Everything seems to work correctly for Android Target (however I can not post images) The application crash when I try to share to iOS Target. Here is the error: *\ Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [UIActivityViewController popoverPresentationController]: unrecognized selector sent to instance 0x16508e70'

MatthijsKamstra commented 9 years ago

same here with ios target (haven't tried android yet)

[UIActivityViewController popoverPresentationController]: unrecognized selector sent to instance 0x15ea1cf0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIActivityViewController popoverPresentationController]: unrecognized selector sent to instance 0x15ea1cf0'
Kotzi commented 9 years ago

You can fix this crash adding a if condition when acceding to popoverPresentationController property in Share.mm file. That property just appeared in iOS8, so it will crash with an early version.

This's working fine: if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){ // Required for iPad activityVC.popoverPresentationController.sourceView = [[UIApplication sharedApplication] keyWindow]; // Remove arrow from action sheet. [activityVC.popoverPresentationController setPermittedArrowDirections:0]; // Set action sheet to middle of view. activityVC.popoverPresentationController.sourceRect = [[UIApplication sharedApplication] keyWindow].frame; }

With this define:

define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

jgranick commented 9 years ago

Would someone mind testing and doing a pull with this change?

fbricker commented 9 years ago

Hi, I can test this on iOS 8 device... but not on lower versions :( If someone can confirm that this works fine on iOS 7 and lower, I'll commit the change :)

jgranick commented 9 years ago

I think these calls are why this extension does not build on our build server:

Error: ./ios/Share.mm:22:20: error: property 'popoverPresentationController' not found on object of type 'UIActivityViewController *'
[14:05:55][Step 1/1]         activityVC.popoverPresentationController.sourceView = [[UIApplication sharedApplication] keyWindow];
[14:05:55][Step 1/1]                    ^
[14:05:55][Step 1/1] ./ios/Share.mm:25:21: error: property 'popoverPresentationController' not found on object of type 'UIActivityViewController *'
[14:05:55][Step 1/1]         [activityVC.popoverPresentationController setPermittedArrowDirections:0];
[14:05:55][Step 1/1]                     ^
[14:05:55][Step 1/1] ./ios/Share.mm:28:20: error: property 'popoverPresentationController' not found on object of type 'UIActivityViewController *'
[14:05:55][Step 1/1]         activityVC.popoverPresentationController.sourceRect = [[UIApplication sharedApplication] keyWindow].frame;
[14:05:55][Step 1/1]                    ^
Kotzi commented 9 years ago

Is the build server updated? maybe it doesn't have the last SDK from Apple and it doesn't recognize that property (I don't really know how it build, but I think that maybe it's failing because of that).

Kotzi commented 9 years ago

I can do a PR, but I have a big mess with tons of repos... so it could take a while :(

fbricker commented 9 years ago

I think it may be safer to surround the code with respondsToSelector like this:

if ([activityVC respondsToSelector:@selector(popoverPresentationController)]) {
    activityVC.popoverPresentationController.sourceView = [[UIApplication sharedApplication] keyWindow];
    [activityVC.popoverPresentationController setPermittedArrowDirections:0]; // Remove arrow from action sheet.
    activityVC.popoverPresentationController.sourceRect = [[UIApplication sharedApplication] keyWindow].frame; // Set action sheet to middle of view.
}
Kotzi commented 9 years ago

Yep, that's more in the Obj-C way :)

fbricker commented 9 years ago

Great, I'll be pushing an update in few minutes. I'm testing now :)

fbricker commented 9 years ago

Done! An update has been published on haxelib :) Thanks guys!

Also, I've deprecated the old "openfl-share" library from haxelib.