- Home /
Question by
Crendel-Studios · May 02, 2017 at 01:16 PM ·
iosscreenshotsharingobjective-c
Native Sharing dialog cause crash on iPad 2 iOS 7.1.2
I'm working on Unity 5.6 mobile game. I'm using native share plugin https://github.com/ChrisMaire/unity-native-sharing to share game link with screenshot. It works like a charm on iPhone 7 with iOS 10, but crashes on iPad 2 with stack trace: Date/Time: 2017-04-27 20:50:44.908 +0300 OS Version: iOS 7.1.2 (11D257) Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
0 <unresolved> 0x2ef46f7e <unresolved>
1 <unresolved> 0x39a2dcca <unresolved>
2 <unresolved> 0x2ef46ec0 <unresolved>
3 <unresolved> 0x319ade70 <unresolved>
4 <unresolved> 0x39a3cb66 <unresolved>
5 mygame 0x6bbcf0 -[iOSNativeShare initWithText:withURL:withImage:withSubject:] (iOSNativeShare.m:134)
6 mygame 0x6bb700 +[iOSNativeShare withText:withURL:withImage:withSubject:] (iOSNativeShare.m:51)
7 mygame 0x6bbdbc _showSocialSharing (iOSNativeShare.m:146)
8 mygame 0x72226 _NativeShare_showSocialSharing_m1817940662 (Bulk_Assembly-CSharp-firstpass_0.cpp:2766)
9 mygame 0x7211c _NativeShare_CallSocialShareAdvanced_m300608371 (Bulk_Assembly-CSharp-firstpass_0.cpp:2825)
10 mygame 0x72090 _NativeShare_Share_m4148598826 (Bulk_Assembly-CSharp-firstpass_0.cpp:2703)
11 mygame 0xd28a8 _U3CshowShareDialogU3Ec__IteratorF_MoveNext_m149489883 (Bulk_Assembly-CSharp_2.cpp:15675)
12 mygame 0x6940c8 RuntimeInvoker_Boolean_t211005341(MethodInfo const*, void*, void**) (Il2CppInvokerTable.cpp:935)
13 mygame 0xecdfa4 il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppObject**) (Runtime.cpp:350)
14 mygame 0x82300e ScriptingInvocation::Invoke(ScriptingException**, bool) (ScriptingInvocation.cpp:180)
15 mygame 0x822fa6 bool ScriptingInvocation::Invoke<bool>(ScriptingException**, bool) (ScriptingInvocation.cpp:131)
16 mygame 0x816a48 Coroutine::InvokeMoveNext(ScriptingException**) (ScriptingInvocation.h:46)
17 mygame 0x8168b6 Coroutine::Run() (Coroutine.cpp:226)
18 mygame 0x7293a6 DelayedCallManager::Update(int) (CallDelayed.cpp:178)
19 mygame 0x7e9ed8 PlayerLoop(bool, bool, IHookEvent*) (Player.cpp:1726)
20 mygame 0xa0148e UnityPlayerLoopImpl(bool) (LibEntryPoint.mm:239)
21 mygame 0x54028 _UnityRepaint (UnityAppController+Rendering.mm:236)
22 mygame 0x53e2c -[UnityAppController(Rendering) repaintDisplayLink] (UnityAppController+Rendering.mm:52)
23 <unresolved> 0x3142fdee <unresolved>
24 <unresolved> 0x3142fb98 <unresolved>
25 <unresolved> 0x3419d758 <unresolved>
26 <unresolved> 0x2fc3244c <unresolved>
27 <unresolved> 0x2ef06ea4 <unresolved>
28 <unresolved> 0x2ef11a62 <unresolved>
29 <unresolved> 0x2ef119fe <unresolved>
30 <unresolved> 0x2ef101d2 <unresolved>
31 <unresolved> 0x2ee7aeba <unresolved>
32 <unresolved> 0x2ee7ac9e <unresolved>
33 <unresolved> 0x33d7565e <unresolved>
34 <unresolved> 0x317c7148 <unresolved>
35 mygame 0x4c816 _main (main.mm:32)
36 <unresolved> 0x39f3aab2 <unresolved>
here is iOSNativeShare.m file: #import "iOSNativeShare.h"
@implementation iOSNativeShare{
}
#ifdef UNITY_4_0 || UNITY_5_0
#import "iPhone_View.h"
#else
extern UIViewController* UnityGetGLViewController();
#endif
+(id) withTitle:(char*)title withMessage:(char*)message{
return [[iOSNativeShare alloc] initWithTitle:title withMessage:message];
}
-(id) initWithTitle:(char*)title withMessage:(char*)message{
self = [super init];
if( !self ) return self;
ShowAlertMessage([[NSString alloc] initWithUTF8String:title], [[NSString alloc] initWithUTF8String:message]);
return self;
}
void ShowAlertMessage (NSString *title, NSString *message){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
}
+(id) withText:(char*)text withURL:(char*)url withImage:(char*)image withSubject:(char*)subject{
return [[iOSNativeShare alloc] initWithText:text withURL:url withImage:image withSubject:subject];
}
-(id) initWithText:(char*)text withURL:(char*)url withImage:(char*)image withSubject:(char*)subject{
self = [super init];
if( !self ) return self;
NSString *mText = text ? [[NSString alloc] initWithUTF8String:text] : nil;
NSString *mUrl = url ? [[NSString alloc] initWithUTF8String:url] : nil;
NSString *mImage = image ? [[NSString alloc] initWithUTF8String:image] : nil;
NSString *mSubject = subject ? [[NSString alloc] initWithUTF8String:subject] : nil;
NSMutableArray *items = [NSMutableArray new];
if(mText != NULL && mText.length > 0){
[items addObject:mText];
}
if(mUrl != NULL && mUrl.length > 0){
NSURL *formattedURL = [NSURL URLWithString:mUrl];
[items addObject:formattedURL];
}
if(mImage != NULL && mImage.length > 0){
if([mImage hasPrefix:@"http"])
{
NSURL *urlImage = [NSURL URLWithString:mImage];
NSError *error = nil;
NSData *dataImage = [NSData dataWithContentsOfURL:urlImage options:0 error:&error];
if (!error) {
UIImage *imageFromUrl = [UIImage imageWithData:dataImage];
[items addObject:imageFromUrl];
} else {
ShowAlertMessage(@"Error", @"Cannot load image");
}
}
else if ( [self isStringValideBase64:mImage]){
NSData* imageBase64Data = [[NSData alloc]initWithBase64Encoding:mImage];
UIImage* image = [UIImage imageWithData:imageBase64Data];
if (image!= nil){
[items addObject:image];
}
else{
ShowAlertMessage(@"Error", @"Cannot load image");
}
}
else{
NSFileManager *fileMgr = [NSFileManager defaultManager];
if([fileMgr fileExistsAtPath:mImage]){
NSData *dataImage = [NSData dataWithContentsOfFile:mImage];
UIImage *imageFromUrl = [UIImage imageWithData:dataImage];
[items addObject:imageFromUrl];
}else{
ShowAlertMessage(@"Error", @"Cannot find image");
}
}
}
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:Nil];
if(mSubject != NULL) {
[activity setValue:mSubject forKey:@"subject"];
} else {
[activity setValue:@"" forKey:@"subject"];
}
UIViewController *rootViewController = UnityGetGLViewController();
//if iPhone
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[rootViewController presentViewController:activity animated:YES completion:Nil];
}
//if iPad
else {
// Change Rect to position Popover
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activity];
[popup presentPopoverFromRect:CGRectMake(rootViewController.view.frame.size.width/2, rootViewController.view.frame.size.height/4, 0, 0)inView:rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
return self;
}
-(BOOL) isStringValideBase64:(NSString*)string{
NSString *regExPattern = @"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$";
NSRegularExpression *regEx = [[NSRegularExpression alloc] initWithPattern:regExPattern options:NSRegularExpressionCaseInsensitive error:nil];
NSUInteger regExMatches = [regEx numberOfMatchesInString:string options:0 range:NSMakeRange(0, [string length])];
return regExMatches != 0;
}
# pragma mark - C API
iOSNativeShare* instance;
void showAlertMessage(struct ConfigStruct *confStruct) {
instance = [iOSNativeShare withTitle:confStruct->title withMessage:confStruct->message];
}
void showSocialSharing(struct SocialSharingStruct *confStruct) {
instance = [iOSNativeShare withText:confStruct->text withURL:confStruct->url withImage:confStruct->image withSubject:confStruct->subject];
}
@end
I'm trying to resolve this crash two days streight, but I have never worked with native iOS development and objective C and even can't figure out how to try\catch this exception and prevent game from crashing.
Comment
Answer by thexdd · Jan 29, 2019 at 03:48 PM
Hi, did you manage to resolve it? I think I am having exact same problem...