From 4c01e0c9df00116f2aa1bf17e4e5c9abf501d04a Mon Sep 17 00:00:00 2001 From: caio.marcelo Date: Thu, 30 Mar 2017 15:17:36 -0300 Subject: [PATCH] Fix IOS Build --- .DS_Store | Bin 0 -> 6148 bytes Assets/.DS_Store | Bin 0 -> 6148 bytes Assets/Plugins/.DS_Store | Bin 0 -> 6148 bytes Assets/Plugins/IOS/.DS_Store | Bin 0 -> 6148 bytes Assets/Plugins/IOS/iOSNativeShare.h | 35 +++++++++++++++++++++++++++++++++++ Assets/Plugins/IOS/iOSNativeShare.h.meta | 23 +++++++++++++++++++++++ Assets/Plugins/IOS/iOSNativeShare.m | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Assets/Plugins/IOS/iOSNativeShare.m.meta | 23 +++++++++++++++++++++++ Assets/Resources/ANIMS/Ç.anim | 2 +- Assets/Scenes/Main.unity | 92 ++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------- Assets/Scripts/.DS_Store | Bin 0 -> 8196 bytes Assets/Scripts/Export Video/ExportVideo.cs | 45 ++++++++++++++++++++------------------------- Assets/Scripts/Export Video/MediaShareIOS.cs | 67 ++++++++++++++++++++++++++++++++++++------------------------------- Assets/Scripts/Export Video/ShareIOS.cs | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Assets/Scripts/Export Video/ShareIOS.cs.meta | 12 ++++++++++++ ProjectSettings/ProjectSettings.asset | 2 +- 16 files changed, 441 insertions(+), 104 deletions(-) create mode 100644 .DS_Store create mode 100644 Assets/.DS_Store create mode 100644 Assets/Plugins/.DS_Store create mode 100644 Assets/Plugins/IOS/.DS_Store create mode 100755 Assets/Plugins/IOS/iOSNativeShare.h create mode 100644 Assets/Plugins/IOS/iOSNativeShare.h.meta create mode 100755 Assets/Plugins/IOS/iOSNativeShare.m create mode 100644 Assets/Plugins/IOS/iOSNativeShare.m.meta create mode 100644 Assets/Scripts/.DS_Store create mode 100644 Assets/Scripts/Export Video/ShareIOS.cs create mode 100644 Assets/Scripts/Export Video/ShareIOS.cs.meta diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..cdce778 Binary files /dev/null and b/.DS_Store differ diff --git a/Assets/.DS_Store b/Assets/.DS_Store new file mode 100644 index 0000000..5e61194 Binary files /dev/null and b/Assets/.DS_Store differ diff --git a/Assets/Plugins/.DS_Store b/Assets/Plugins/.DS_Store new file mode 100644 index 0000000..907e703 Binary files /dev/null and b/Assets/Plugins/.DS_Store differ diff --git a/Assets/Plugins/IOS/.DS_Store b/Assets/Plugins/IOS/.DS_Store new file mode 100644 index 0000000..b6c798e Binary files /dev/null and b/Assets/Plugins/IOS/.DS_Store differ diff --git a/Assets/Plugins/IOS/iOSNativeShare.h b/Assets/Plugins/IOS/iOSNativeShare.h new file mode 100755 index 0000000..a160c60 --- /dev/null +++ b/Assets/Plugins/IOS/iOSNativeShare.h @@ -0,0 +1,35 @@ +#import "UnityAppController.h" + +@interface iOSNativeShare : UIViewController +{ + UINavigationController *navController; +} + + +struct ConfigStruct { + char* title; + char* message; +}; + +struct SocialSharingStruct { + char* text; + char* url; + char* image; + char* subject; +}; + + +#ifdef __cplusplus +extern "C" { +#endif + + void showAlertMessage(struct ConfigStruct *confStruct); + void showSocialSharing(struct SocialSharingStruct *confStruct); + void sendToGallery(struct ConfigStruct *confStruct); + +#ifdef __cplusplus +} +#endif + + +@end diff --git a/Assets/Plugins/IOS/iOSNativeShare.h.meta b/Assets/Plugins/IOS/iOSNativeShare.h.meta new file mode 100644 index 0000000..a1121d1 --- /dev/null +++ b/Assets/Plugins/IOS/iOSNativeShare.h.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: c9d0251cf02d34161b7a753f8a2c1fee +timeCreated: 1490842313 +licenseType: Free +PluginImporter: + serializedVersion: 1 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + platformData: + Any: + enabled: 0 + settings: {} + Editor: + enabled: 0 + settings: + DefaultValueInitialized: true + iOS: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/IOS/iOSNativeShare.m b/Assets/Plugins/IOS/iOSNativeShare.m new file mode 100755 index 0000000..e95723f --- /dev/null +++ b/Assets/Plugins/IOS/iOSNativeShare.m @@ -0,0 +1,173 @@ +#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; + +} + ++(id) withTitle:(char*)path{ + + return [[iOSNativeShare alloc] initWithTitle:path]; +} + +-(id) initWithTitle:(char*)path { + + self = [super init]; + + if( !self ) return self; + + SendToGallery([[NSString alloc] initWithUTF8String:path]); + + return self; + +} + +void SendToGallery(NSString *path){ + if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(path)){ + UISaveVideoAtPathToSavedPhotosAlbum (path,nil, nil, nil); + } +} + +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]; + NSArray *postItems = [NSArray new]; + + if(mImage != NULL && mImage.length > 0){ + + NSFileManager *fileMgr = [NSFileManager defaultManager]; + if([fileMgr fileExistsAtPath:mImage]){ + + //NSData *dataImage = [NSData dataWithContentsOfFile:mImage]; + + // UIImage *imageFromUrl = [UIImage imageWithData:dataImage]; + NSData *data = [[NSData alloc] initWithContentsOfFile:mImage]; + NSURL *videoURL = [NSURL fileURLWithPath:mImage]; + + // [items addObject:videoURL]; + postItems = @[videoURL]; + //NSArray *postItems = @[videoURL]; + }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]; + // } + + UIActivityViewController *activityVc = [[UIActivityViewController alloc]initWithActivityItems:postItems applicationActivities:nil]; + if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && [activityVc respondsToSelector:@selector(popoverPresentationController)] ) { + UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVc]; + [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0) + inView:[UIApplication sharedApplication].keyWindow.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; + } + else + [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:activityVc animated:YES completion:nil]; + + + 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 sendToGallery(struct ConfigStruct *confStruct) { + instance = [iOSNativeShare withTitle:confStruct->title]; +} + +void showSocialSharing(struct SocialSharingStruct *confStruct) { + instance = [iOSNativeShare withText:confStruct->text withURL:confStruct->url withImage:confStruct->image withSubject:confStruct->subject]; +} + +@end diff --git a/Assets/Plugins/IOS/iOSNativeShare.m.meta b/Assets/Plugins/IOS/iOSNativeShare.m.meta new file mode 100644 index 0000000..ca034bc --- /dev/null +++ b/Assets/Plugins/IOS/iOSNativeShare.m.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 811884d43308440c69d9b36ec817ceed +timeCreated: 1490842313 +licenseType: Free +PluginImporter: + serializedVersion: 1 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + platformData: + Any: + enabled: 0 + settings: {} + Editor: + enabled: 0 + settings: + DefaultValueInitialized: true + iOS: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/ANIMS/Ç.anim b/Assets/Resources/ANIMS/Ç.anim index d16eeac..80f699d 100644 --- a/Assets/Resources/ANIMS/Ç.anim +++ b/Assets/Resources/ANIMS/Ç.anim @@ -5,7 +5,7 @@ AnimationClip: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} - m_Name: "\xC7" + m_Name: "C\u0327" serializedVersion: 6 m_Legacy: 1 m_Compressed: 0 diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 58017da..6766003 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -3592,53 +3592,53 @@ Animation: m_GameObject: {fileID: 535548070} m_Enabled: 1 serializedVersion: 3 - m_Animation: {fileID: 7400000, guid: 365e5f41595503c48915848d883fabfe, type: 2} + m_Animation: {fileID: 7400000, guid: e0b82ea10d92c45a49236639d7e127a7, type: 2} m_Animations: - - {fileID: 7400000, guid: f1f36f20657e5244e9c1e21117d9a452, type: 2} - - {fileID: 7400000, guid: 55bec2c04d14e74488ef127ee380a080, type: 2} - - {fileID: 7400000, guid: b368bfe0efa37c04bb9c661058ccedb9, type: 2} - - {fileID: 7400000, guid: 365e5f41595503c48915848d883fabfe, type: 2} - - {fileID: 7400000, guid: fa9ef8a15fe08a143bc89dc00289fc17, type: 2} - - {fileID: 7400000, guid: 939bebf16bb2dba44894c5745c5dc1f8, type: 2} - - {fileID: 7400000, guid: aecdf652be04b444f84644ba7c403960, type: 2} - - {fileID: 7400000, guid: 53ed20623f5573345a4fb057db454b05, type: 2} - - {fileID: 7400000, guid: b0bafda258c57414ebfbc4cf89719795, type: 2} - - {fileID: 7400000, guid: 67caa6e2d05387848a9448b57fffcb0f, type: 2} - - {fileID: 7400000, guid: a79227e28dd60fa4c9812a51ab9d455e, type: 2} - - {fileID: 7400000, guid: 8b1d930398178064795f5d23af67dce4, type: 2} - - {fileID: 7400000, guid: af8192a32a30ab746be40ff1dcb8bc0a, type: 2} - - {fileID: 7400000, guid: e282c734045b47241988e2b9fdf0dc7e, type: 2} - - {fileID: 7400000, guid: 698d03f46785361449a10cc0003862eb, type: 2} - - {fileID: 7400000, guid: e193836512c744c4299651990fc3ca10, type: 2} - - {fileID: 7400000, guid: c4d452a56e2f4ee4a83e5679f969a354, type: 2} - - {fileID: 7400000, guid: 220a675640cc72d4f9c8d364c9a377b4, type: 2} - - {fileID: 7400000, guid: 9a1e34a6954967f4fb3982394bf61eef, type: 2} - - {fileID: 7400000, guid: 039911b68664f7b40b97e2665893a1e5, type: 2} - - {fileID: 7400000, guid: b4a4a507b5b85404f9ca30cf2855b359, type: 2} - - {fileID: 7400000, guid: 3b67cb87e08f4e34badc00f7b49d2591, type: 2} - - {fileID: 7400000, guid: dc854de773a9e3f488c7a1b42d6a460b, type: 2} - - {fileID: 7400000, guid: 21b376087ddd4ec46a1da0c3ba1181d9, type: 2} - - {fileID: 7400000, guid: db84b318b67dbc54fa1fab6d31dfeb6e, type: 2} - - {fileID: 7400000, guid: 47e5da18eda740844ba111cfab49d0eb, type: 2} - - {fileID: 7400000, guid: ba9dc32834cf193429f27449b1d9d701, type: 2} - - {fileID: 7400000, guid: 22f7b3c892f0e5e41b120798d7953026, type: 2} - - {fileID: 7400000, guid: 9396f2d833a082446b36b0cda61ba87c, type: 2} - - {fileID: 7400000, guid: 289449396bffd4045b8657269df378f2, type: 2} - - {fileID: 7400000, guid: 99bb7e6adbe6d5f4984c51d5d5e92045, type: 2} - - {fileID: 7400000, guid: b6faf58a03a0dc24cb9777c70fda828b, type: 2} - - {fileID: 7400000, guid: b2b18bfa970783a4ab32945b1c4bc54b, type: 2} - - {fileID: 7400000, guid: a8b0488b23a43b3499d2b1d8b81f0707, type: 2} - - {fileID: 7400000, guid: ccdf6bab5e56c0447abfc0a8f745b62c, type: 2} - - {fileID: 7400000, guid: 8d2c7cdb67fea144e9660db7edd82239, type: 2} - - {fileID: 7400000, guid: 6191f3fb2e8027b48ac60aa48c11065d, type: 2} - - {fileID: 7400000, guid: dbf77a3c567182846bad50598584109d, type: 2} - - {fileID: 7400000, guid: d2f41e4d1ce31a4458ccdab2cd91faae, type: 2} - - {fileID: 7400000, guid: fc72e7fd88de0b94fb9b050fc1368547, type: 2} - - {fileID: 7400000, guid: 5b7bf0ae891107f4aaa366ba42eac9ee, type: 2} - - {fileID: 7400000, guid: d9c72b1fb167df045ae7ac711d1dee6c, type: 2} - - {fileID: 7400000, guid: d927185f3fb021844834f7086d346e3a, type: 2} - - {fileID: 7400000, guid: e62d77cfc7d0d104b84d8beb5ef72c33, type: 2} - - {fileID: 7400000, guid: 1dd400df2179f94469eb2480a313a8cf, type: 2} + - {fileID: 7400000, guid: 094c9782dfd1a4419b4300050525a196, type: 2} + - {fileID: 7400000, guid: 0a25b7eb696464a9ba3fedba28052f44, type: 2} + - {fileID: 7400000, guid: 212a470f4d8764d3aab828715dcceadd, type: 2} + - {fileID: 7400000, guid: 24ccfe8cc110546aab2e9ea1edab0997, type: 2} + - {fileID: 7400000, guid: 255d4ddbbcdac46d9917908e6dc83fbf, type: 2} + - {fileID: 7400000, guid: 2fdb4638c75f24f0aabd6cc76fb610c4, type: 2} + - {fileID: 7400000, guid: 353f223b7116a4871a1ed9cb10953fec, type: 2} + - {fileID: 7400000, guid: 38aa20a48a06548d9946da7f3491fd79, type: 2} + - {fileID: 7400000, guid: 3953996c14ada434e8bece627ea272fb, type: 2} + - {fileID: 7400000, guid: 3b02e44ef03c5471c873718351272938, type: 2} + - {fileID: 7400000, guid: 3ff67392ee17d46e8b75e23614754596, type: 2} + - {fileID: 7400000, guid: 46db7a3a687d6491c87b272ba4a3af9b, type: 2} + - {fileID: 7400000, guid: 48640d5b0a6804e8a892d7e3f9878338, type: 2} + - {fileID: 7400000, guid: 6867e7a4c4a93433b85dd978831a5789, type: 2} + - {fileID: 7400000, guid: 723477075e06c43dca279006c68f629a, type: 2} + - {fileID: 7400000, guid: 75289ce9809d340a39e5d2d9896ef14e, type: 2} + - {fileID: 7400000, guid: 773b86077b0a9459eb0d40f9c6147238, type: 2} + - {fileID: 7400000, guid: 7ccd4c6ab0ec54ceaa2946562f1a9498, type: 2} + - {fileID: 7400000, guid: 7f65fa3885c054b49ae6e5271be81d3f, type: 2} + - {fileID: 7400000, guid: 8043026f4179c4e36bf9c52857439067, type: 2} + - {fileID: 7400000, guid: 829700cfb4bf84f01a308423418d482d, type: 2} + - {fileID: 7400000, guid: 87310cd5c3519409081aad5bc7d001f4, type: 2} + - {fileID: 7400000, guid: 8b46d8bdc57654882b802d8a424bbc64, type: 2} + - {fileID: 7400000, guid: 8c3b08031b41a4af6a38cddd30b6b711, type: 2} + - {fileID: 7400000, guid: 922333c7fb2f24607a2b6bc7eddc0c92, type: 2} + - {fileID: 7400000, guid: 93c97cf7199d14c8a85c6a47dfe96fdd, type: 2} + - {fileID: 7400000, guid: 99e6d1fa06bef4cffb3985c33858ab7f, type: 2} + - {fileID: 7400000, guid: 9a03fa44cc4e74406a490fa7a601eb2d, type: 2} + - {fileID: 7400000, guid: 9d20ba4e0319344f29101e050835449a, type: 2} + - {fileID: 7400000, guid: 9f404de03117c44fcbf5c4bebbdebc39, type: 2} + - {fileID: 7400000, guid: 9fac8b289e9c34268bade7f7dc070255, type: 2} + - {fileID: 7400000, guid: a2f710de3a93149d981cfd3643c29f5d, type: 2} + - {fileID: 7400000, guid: a55f62e68785e4f16b38373c27770c2c, type: 2} + - {fileID: 7400000, guid: ad8d4c5f8f40746fb809287d36da0da4, type: 2} + - {fileID: 7400000, guid: b0298c4a0832c4567a80f0293805f766, type: 2} + - {fileID: 7400000, guid: b90260b13c6b043008a3231f0e325d8b, type: 2} + - {fileID: 7400000, guid: bd4784c7f8ccc4dd6b9c0d3bca313258, type: 2} + - {fileID: 7400000, guid: d3a14cd4d3aef472f81d58456286f1da, type: 2} + - {fileID: 7400000, guid: d902aa4db6b5e44fe9153e04e901b357, type: 2} + - {fileID: 7400000, guid: d9a3268b5233b489489a6b406f5b560d, type: 2} + - {fileID: 7400000, guid: daceeb12c57434b03ab14733724787b0, type: 2} + - {fileID: 7400000, guid: e0b82ea10d92c45a49236639d7e127a7, type: 2} + - {fileID: 7400000, guid: e0e4fafd1c404477a9330c24fad5c5d5, type: 2} + - {fileID: 7400000, guid: e5df376619b5547418da0a4bb053a736, type: 2} + - {fileID: 7400000, guid: edc0fe305be934cfdaf262b2372efc9f, type: 2} m_WrapMode: 0 m_PlayAutomatically: 1 m_AnimatePhysics: 0 diff --git a/Assets/Scripts/.DS_Store b/Assets/Scripts/.DS_Store new file mode 100644 index 0000000..ab366be Binary files /dev/null and b/Assets/Scripts/.DS_Store differ diff --git a/Assets/Scripts/Export Video/ExportVideo.cs b/Assets/Scripts/Export Video/ExportVideo.cs index 900ec97..b2e2472 100644 --- a/Assets/Scripts/Export Video/ExportVideo.cs +++ b/Assets/Scripts/Export Video/ExportVideo.cs @@ -37,6 +37,7 @@ public class ExportVideo : MonoBehaviour { public ScreenManager screenManager; public MediaShareIOS MediaShareIOS; + private MediaShareIOS share = new MediaShareIOS(); private const string SERVER_URL = "http://150.165.205.84:80/video"; @@ -44,7 +45,7 @@ public class ExportVideo : MonoBehaviour { private static string gloss = "Gloss"; - /* Strings related to the Android Dialog*/ + /* Strings related to the IOS Dialog*/ private string title = "Download"; private string message = "Para compartilhar é preciso realizar o download do vídeo. Tamanho do Download: "; private string yesOp = "DOWNLOAD"; @@ -81,26 +82,16 @@ public class ExportVideo : MonoBehaviour { private void onClickExport() { PlayerLogger.Log("ExportVideo", "OnClickExport", "Starting Export..."); - - /* Aqui é o começo do processo de Exportar vídeo. Antes do processo realmente começar, deve-se checar se o app tem permissões para escrever - * no aparelho. Deve-se então trocar essa parte do código por uma abordagem iOS. NÃO ESQUECER DO CALLBACK PERMITTED. Caso contrário não - * será direcionado para próxima etapa do processo.*/ - - - /* - NoodlePermissionGranter.PermissionRequestCallback = Permitted; - NoodlePermissionGranter.GrantPermission(NoodlePermissionGranter.NoodleAndroidPermission.WRITE_EXTERNAL_STORAGE); - */ - Permitted(true); + export(); } - private void Permitted(bool PermissionGranted) + private void export() { - if (PermissionGranted) + if (true) { int fiveTimesCount; @@ -280,18 +271,17 @@ public class ExportVideo : MonoBehaviour { Action errorAction = () => { screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); - /*new AndroidToast().showToast("Erro ao compartilhar mídia.", "LONG");*/ + + share.showAlert ("Vlibras Vídeo","Erro ao compartilhar mídia."); }; - - /*Essa chamada é a que compartilha o video baixado, criando a intent. Achar equivalente no iOS. NÃO ESQUECER DO - * CALLBACK "errorAction", o qual é chamado quando não se pode compartilhar o vídeo.*/ - StartCoroutine(MediaShareIOS.ShareIntent(errorAction)); + StartCoroutine(share.ShareIntent(errorAction)); } else { /*new AndroidToast().showToast("Erro ao compartilhar mídia.", "LONG");*/ screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); + share.showAlert ("Vlibras Vídeo","Erro ao compartilhar mídia."); } @@ -498,6 +488,7 @@ public class ExportVideo : MonoBehaviour { private IEnumerator videoDownload() { videoDownloadRunning = true; + WWW DownloadVideo = new WWW(SERVER_URL + "/" + videoFile); while (!DownloadVideo.isDone) @@ -540,11 +531,10 @@ public class ExportVideo : MonoBehaviour { { bytes = DownloadVideo.bytesDownloaded; videoContent = DownloadVideo.bytes; - Action callBack = () => { OnDownloadFinished();/* new AndroidToast().showToast("Vídeo salvo na Galeria.", "SHORT");*/ }; - Action errorWriting = () => { screenManager.changeExportStates(ExportLayers.ExportLayer.All, true); }; - videoDownloadRunning = false; - StartCoroutine(MediaShareIOS.WriteOnIOS(videoContent, bytes, System.DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss"), callBack, errorWriting)); - + Action callBack = () => { OnDownloadFinished(); share.showAlert("Vlibras Vídeo", "Vídeo salvo na Galeria."); }; + Action errorWriting = () => { screenManager.changeExportStates(ExportLayers.ExportLayer.All, true);share.showAlert ("Vlibras Vídeo","Erro ao salvar vídeo, tente novamente."); }; + videoDownloadRunning = false; + StartCoroutine(share.WriteOnIOS(videoContent, bytes, System.DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss"), callBack, errorWriting)); } else { @@ -586,20 +576,25 @@ public class ExportVideo : MonoBehaviour { { switch (error) { - case ExportLayers.ConnectionStatusError.CONNECTION_TIMEOUT_FAILURE: + case ExportLayers.ConnectionStatusError.CONNECTION_TIMEOUT_FAILURE: /*new AndroidToast().showToast("Erro de conexão. Tente novamente.", "LONG");*/ + share.showAlert ("Vlibras Vídeo","Erro de conexão. Tente novamente."); break; case ExportLayers.ConnectionStatusError.DOWNLOAD_CONNECTION_FAILURE: /* new AndroidToast().showToast("Erro ao efetuar download, tente novamente.", "LONG");*/ + share.showAlert ("Vlibras Vídeo","Erro ao efetuar download, tente novamente."); break; case ExportLayers.ConnectionStatusError.INTERNET_CONNECTION_FAILURE: /* new AndroidToast().showToast("Não há acesso à internet. Verifique sua conexão", "LONG");*/ + share.showAlert ("Vlibras Vídeo","Não há acesso à internet. Verifique sua conexão"); break; case ExportLayers.ConnectionStatusError.ERROR_CONNECTION_FAILURE: /* new AndroidToast().showToast("Problema na conexão. Aguarde e tente novamente.", "LONG");*/ + share.showAlert ("Vlibras Vídeo","Problema na conexão. Aguarde e tente novamente."); break; default: /*new AndroidToast().showToast("Ocorreu um erro. Estamos trabalhando para solucioná-lo!", "LONG");*/ + share.showAlert ("Vlibras Vídeo","Ocorreu um erro. Estamos trabalhando para solucioná-lo!"); break; } diff --git a/Assets/Scripts/Export Video/MediaShareIOS.cs b/Assets/Scripts/Export Video/MediaShareIOS.cs index cb11e54..9ef0083 100644 --- a/Assets/Scripts/Export Video/MediaShareIOS.cs +++ b/Assets/Scripts/Export Video/MediaShareIOS.cs @@ -14,6 +14,8 @@ *Author: Thiago Filipe *thiago.filipe@lavid.ufpb.br ***********************/ + + using UnityEngine; using System.Collections; using System; @@ -22,36 +24,22 @@ using System.IO; -public class MediaShareIOS : MonoBehaviour -{ - - private string MediaType = "video/*"; +public class MediaShareIOS : MonoBehaviour { private static string path; private string VlibrasFolder = "VLibras"; private string Filen = "VLibrasVideo_"; private static string FilePath = ""; - /*Makes sure that Vlibras Folder gets created and write the video bytes in it.*/ - public void Awake() - { - path = Path.Combine(Application.persistentDataPath, VlibrasFolder); - } + public IEnumerator WriteOnIOS(byte[] videoContent, int bytes,string CurrentTime, Action finishWriting, Action errorWriting) - { + { + path = Application.persistentDataPath; + PlayerLogger.Log("ExportVideo", "VideoDownload", "Writing at: " + path); /*FilePath se refere ao nome que o arquivo será salvo. Este deve ser mantido como está.*/ FilePath = Filen + CurrentTime + ".mp4"; - - /* A partir daqui deve ser feita a implementação IOS, onde deve-se utilizar dos callbacks "finishWriting" e "errorWriting". O primeiro - * chamado em caso de sucesso na escrita do vídeo, o segundo em caso de algum erro.*/ - /*É necessário que o arquivo seja salvo numa pasta própria do Vlibras de maneira que o usuário iOS possa visualizar o vídeo na galeria*/ - - - - /* Checking if folder Vlibras exists*/ - DirectoryInfo dir = new DirectoryInfo(path); if (!dir.Exists) { @@ -61,11 +49,11 @@ public class MediaShareIOS : MonoBehaviour try { FileStream SourceStream = new FileStream(Path.Combine(path, FilePath), FileMode.OpenOrCreate); - if (SourceStream.CanWrite) { SourceStream.Write(videoContent, 0, bytes); SourceStream.Close(); + ShareIOS.CallSendToGallery(Path.Combine(path,FilePath)); finishWriting(); yield break; @@ -74,6 +62,7 @@ public class MediaShareIOS : MonoBehaviour else { // new AndroidToast().showToast("Erro ao salvar vídeo.", "LONG"); + errorWriting(); } @@ -81,10 +70,8 @@ public class MediaShareIOS : MonoBehaviour } catch (Exception e) { - PlayerLogger.Log("MediaShareAndroid", "WriteOnAndroid", "Message: " + e.Message); - PlayerLogger.Log("MediaShareAndroid", "WriteOnAndroid", "Message: " + e.StackTrace); - // new AndroidToast().showToast("Você precisa dá permissão ao aplicativo", "LONG"); - + PlayerLogger.Log("MediaShareIOS", "WriteOnIOS", "Message: " + e.Message); + PlayerLogger.Log("MediaShareIOS", "WriteOnIOS", "Message: " + e.StackTrace); errorWriting(); } @@ -92,19 +79,37 @@ public class MediaShareIOS : MonoBehaviour } + public void showAlert(string title,string message){ + ShareIOS.CallSocialShare (title, message); + } /* Calling Android Services to create Share Intent*/ public IEnumerator ShareIntent(Action errorAction) { - /* Aqui deve ser feita a implementação iOS da função que permitirá o usuário compartilhar o vídeo com as redes sociais*/ - /*O callback errorAction deve ser chamado em caso de algum erro no processo, por exemplo: usuário baixou o vídeo e foi salvo - * corretamente, porém antes de clicar compartilhar, ele foi no diretório do vídeo e o excluiu, para então clicar compartilhar.*/ - + #if UNITY_IOS + if(File.Exists(Path.Combine(path,FilePath))){ + ShareIOS share = new ShareIOS(); + PlayerLogger.Log("MediaShareIOS","ShareIntent","Trying to share video."); + try{ + share.Share("Vlibras Video",Path.Combine(path,FilePath),"",""); + }catch(Exception e){ + PlayerLogger.Log("MediaShareIOS", "ShareIntent", "Message: " + e.Message); + PlayerLogger.Log("MediaShareIOS", "ShareIntent", "Message: " + e.StackTrace); + errorAction(); + } + + }else{ + PlayerLogger.Log("MediaShareIOS","ShareIntent","File doesnt exist"); + errorAction(); + } + + + //GeneralSharingiOSBridge.ShareTextWithImage (Path.Combine(path, FilePath), "Vlibras video"); + #endif + yield break; } -} - - +} \ No newline at end of file diff --git a/Assets/Scripts/Export Video/ShareIOS.cs b/Assets/Scripts/Export Video/ShareIOS.cs new file mode 100644 index 0000000..6d97a02 --- /dev/null +++ b/Assets/Scripts/Export Video/ShareIOS.cs @@ -0,0 +1,71 @@ +using UnityEngine; +using System.Collections; +using System.Runtime.InteropServices; +using System.IO; + +/* + * https://github.com/ChrisMaire/unity-native-sharing + */ + +public class ShareIOS : MonoBehaviour { + + public void Share(string shareText, string imagePath, string url, string subject) + { + #if UNITY_IOS + CallSocialShareAdvanced(shareText, subject, url, imagePath); + #else + Debug.Log("No sharing set up for this platform."); + #endif + } + + #if UNITY_IOS + public struct ConfigStruct + { + public string title; + public string message; + } + + [DllImport ("__Internal")] private static extern void showAlertMessage(ref ConfigStruct conf); + + public struct SocialSharingStruct + { + public string text; + public string url; + public string image; + public string subject; + } + + [DllImport ("__Internal")] private static extern void showSocialSharing(ref SocialSharingStruct conf); + + + public static void CallSocialShare(string title, string message) + { + ConfigStruct conf = new ConfigStruct(); + conf.title = title; + conf.message = message; + showAlertMessage(ref conf); + } + + + public static void CallSocialShareAdvanced(string defaultTxt, string subject, string url, string img) + { + SocialSharingStruct conf = new SocialSharingStruct(); + conf.text = defaultTxt; + conf.url = url; + conf.image = img; + conf.subject = subject; + + showSocialSharing(ref conf); + } + [DllImport ("__Internal")] private static extern void sendToGallery(ref ConfigStruct conf); + + public static void CallSendToGallery(string path){ + ConfigStruct conf = new ConfigStruct (); + conf.title = path; + conf.message = ""; + sendToGallery (ref conf); + + } + + #endif +} diff --git a/Assets/Scripts/Export Video/ShareIOS.cs.meta b/Assets/Scripts/Export Video/ShareIOS.cs.meta new file mode 100644 index 0000000..439951e --- /dev/null +++ b/Assets/Scripts/Export Video/ShareIOS.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 184b416e499e94d8ba8d1a429c05c11f +timeCreated: 1490842858 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index e53b088..35ecdf3 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -119,7 +119,7 @@ PlayerSettings: VertexChannelCompressionMask: serializedVersion: 2 m_Bits: 238 - iPhoneSdkVersion: 989 + iPhoneSdkVersion: 988 iPhoneTargetOSVersion: 22 tvOSSdkVersion: 0 tvOSTargetOSVersion: 900 -- libgit2 0.21.2