diff --git a/ios/Classes/SwiftCremeSharingPlugin.swift b/ios/Classes/SwiftCremeSharingPlugin.swift index f4201de..b978067 100644 --- a/ios/Classes/SwiftCremeSharingPlugin.swift +++ b/ios/Classes/SwiftCremeSharingPlugin.swift @@ -10,6 +10,17 @@ public class SwiftCremeSharingPlugin: NSObject, FlutterPlugin { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { switch (call.method){ + case "instagramIsAvailableToShare": + if let storiesUrl = URL(string: "instagram-stories://share") { + if UIApplication.shared.canOpenURL(storiesUrl) { + if #available(iOS 10.0, *) { + return result(true) + } + return result(false) + } else { + return result(false) + } + } case "shareToInstagramStories": if let storiesUrl = URL(string: "instagram-stories://share") { if UIApplication.shared.canOpenURL(storiesUrl) { @@ -45,11 +56,11 @@ public class SwiftCremeSharingPlugin: NSObject, FlutterPlugin { ] UIPasteboard.general.setItems([pasteboardItems], options: pasteboardOptions) UIApplication.shared.open(storiesUrl, options: [:], completionHandler: nil) - return result("User have instagram on their device.") + return result(nil) } - return result("work only in IOS 10.0 or newer") + return result(nil) } else { - result("User doesn't have instagram on their device.") + return result(nil) } } default: diff --git a/lib/creme_sharing.dart b/lib/creme_sharing.dart index 7f8a7f1..cc3e193 100644 --- a/lib/creme_sharing.dart +++ b/lib/creme_sharing.dart @@ -24,6 +24,26 @@ class CremeSharing { _httpClient.close(force: true); } + /// This method will check is the user have the Instagram available to share + Future instagramIsAvailableToShare({ + Color? backgroundTopColor, + Color? backgroundBottomColor, + String? stickerImage, + String? backgroundVideo, + String? backgroundImage, + String? contentURL, + }) => + CremeSharingPlatform.instance.instagramIsAvailableToShare(); + + /// All the arguments are the same of the documentation in https://developers.facebook.com/docs/sharing/sharing-to-stories + /// but in the IOS side you can: + /// - [backgroundTopColor] : will be transformed to a String in hex color + /// - [backgroundBottomColor] : will be transformed to a String in hex color + /// - [stickerImage] : will be transformed to an image if the value be a URL or an image encoded 64 as String + /// - [backgroundImage] : will be transformed to an image if the value be an URL or an image encoded 64 as String + /// - [backgroundVideo] : will be transformed to an image if the value be an URL + /// - [contentURL] : it will be a string (that don't work because the app need to be a partner of Instagram) + /// but in the Android will be implemented (WIP) Future shareToInstagramStories({ Color? backgroundTopColor, Color? backgroundBottomColor, @@ -31,16 +51,15 @@ class CremeSharing { String? backgroundVideo, String? backgroundImage, String? contentURL, - }) { - return CremeSharingPlatform.instance.shareToInstagramStories( - backgroundTopColor: backgroundTopColor, - backgroundBottomColor: backgroundBottomColor, - stickerImage: stickerImage, - backgroundVideo: backgroundVideo, - backgroundImage: backgroundImage, - contentURL: contentURL, - ); - } + }) => + CremeSharingPlatform.instance.shareToInstagramStories( + backgroundTopColor: backgroundTopColor, + backgroundBottomColor: backgroundBottomColor, + stickerImage: stickerImage, + backgroundVideo: backgroundVideo, + backgroundImage: backgroundImage, + contentURL: contentURL, + ); /// This method should be used to share some creator to Instagram stories /// and the mockup can be found on: https://www.figma.com/file/r5ox3y5gRNFXPDb1KcsQS3/CREME-2022?node-id=2316%3A217770 diff --git a/lib/creme_sharing_method_channel.dart b/lib/creme_sharing_method_channel.dart index 54b70c5..17f01ad 100644 --- a/lib/creme_sharing_method_channel.dart +++ b/lib/creme_sharing_method_channel.dart @@ -12,6 +12,18 @@ class MethodChannelCremeSharing extends CremeSharingPlatform { @visibleForTesting final methodChannel = const MethodChannel('creme_sharing'); + @override + Future instagramIsAvailableToShare() async { + if (Platform.isIOS) { + return (await methodChannel + .invokeMethod('instagramIsAvailableToShare') ?? + false); + } + + /// TODO: implement Android + return super.instagramIsAvailableToShare(); + } + @override Future shareToInstagramStories({ Color? backgroundTopColor, @@ -38,6 +50,8 @@ class MethodChannelCremeSharing extends CremeSharingPlatform { }, ); } + + /// TODO: implement Android return super.shareToInstagramStories( contentURL: contentURL, backgroundTopColor: backgroundTopColor, diff --git a/lib/creme_sharing_platform_interface.dart b/lib/creme_sharing_platform_interface.dart index 7b6ccaa..b436c2e 100644 --- a/lib/creme_sharing_platform_interface.dart +++ b/lib/creme_sharing_platform_interface.dart @@ -25,6 +25,10 @@ abstract class CremeSharingPlatform extends PlatformInterface { _instance = instance; } + Future instagramIsAvailableToShare() { + throw UnimplementedError('platformVersion() has not been implemented.'); + } + Future shareToInstagramStories({ Color? backgroundTopColor, Color? backgroundBottomColor,