Skip to content

Commit

Permalink
appinio_social_share - version 0.2.5
Browse files Browse the repository at this point in the history
* Feat: share multiple files

* fix

* fix: names

* Update README.md

* updating facebook sdk version

* Update README.md

* Update README.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* share to tiktok

* Update README.md

* Update README.md

* Update README.md

* fixing tiktok

* Update README.md

* appinio_social_share - version 0.3.0

---------

Co-authored-by: Bilal <[email protected]>
  • Loading branch information
khanmujeeb687 and bilalhamud authored Dec 21, 2023
1 parent bd9f10e commit b267516
Show file tree
Hide file tree
Showing 15 changed files with 442 additions and 209 deletions.
6 changes: 6 additions & 0 deletions packages/appinio_social_share/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.3.0] - 2023.12.21
* Enhancement:
- Facebook Android Sdk updated to 16.0.0.
* Features:
- Now you can share multiple files to whatsapp, telegram, facebook and other apps.

## [0.2.6] - 2023.09.25

* Enhancements:
Expand Down
201 changes: 190 additions & 11 deletions packages/appinio_social_share/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ After created your own file provider and define your own path paste them into th
android:exported="true" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token" />
<meta-data android:name="com.facebook.sdk.ApplicationName" android:value="${applicationName}"/>
<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="${applicationName}" />
```


Expand Down Expand Up @@ -212,6 +214,183 @@ FBSDKCoreKit.ApplicationDelegate.shared.application(

<br />

***If you want to share files to tiktok (iOS), you can follow the steps below. For sharing to android you don't need these steps.***

Step 1 - Install Tiktok Sdk

```
Add the library to your XCode project as a Swift Package:
1- In XCode, click File -> Add Packages...
2- Paste the repository URL: https://github.com/tiktok/tiktok-opensdk-ios
3- Select Dependency Rule -> Up to Next Major Version and input the major version you want (i.e. 2.2.0 You can find the latest release here.)
4- Select Add to Project -> Your project
5- Click Copy Dependency and select the TikTokOpenShareSDK, TiktokOpenCoreSdk libraries.
```

Step 2 - Configure your project

-Configure your Xcode project
-Open your Info.plist file and add or update the following key-value pairs:
-Add the following values to LSApplicationQueriesSchemes:
1. tiktokopensdk for Login Kit.
2. tiktoksharesdk for Share Kit.
3. snssdk1233 and snssdk1180 to check if TikTok is installed on your device.
4. Add TikTokClientKey key with your app's client key, obtained from the TikTok for Developers website, as the value.
5. Add your app's client key to CFBundleURLSchemes.
```plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tiktokopensdk</string>
<string>tiktoksharesdk</string>
<string>snssdk1180</string>
<string>snssdk1233</string>
</array>
<key>TikTokClientKey</key>
<string>$TikTokClientKey</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>$TikTokClientKey</string>
</array>
</dict>
</array>
```

Step 3 - Add the following code to your app's AppDelegate:

```swift

import UIKit
import Flutter
import TikTokOpenSDKCore
import TikTokOpenShareSDK
import Foundation
import Photos

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let cntrl : FlutterViewController = self.window?.rootViewController as! FlutterViewController
let tiktok_channel = FlutterMethodChannel(name: "appinio_social_share_tiktok", binaryMessenger: cntrl.binaryMessenger)

tiktok_channel.setMethodCallHandler(
{
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if call.method == "tiktok_post" {
let args = call.arguments as? [String: Any?]
self.shareVideoToTiktok(args: args!, result: result)
}else{
result("Not implemented!")
}
})


GeneratedPluginRegistrant.register(with: self)
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}




override func application(_ app: UIApplication,open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if (TikTokURLHandler.handleOpenURL(url)) {
return true
}
return false
}

override func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if (TikTokURLHandler.handleOpenURL(userActivity.webpageURL)) {
return true
}
return false
}


func shareVideoToTiktok(args : [String: Any?],result: @escaping FlutterResult) {
let videoFile = args["videoFile"] as? String
let redirectUrl = args["redirectUrl"] as? String
let fileType = args["fileType"] as? String
let videoData = try? Data(contentsOf: URL(fileURLWithPath: videoFile!)) as NSData


PHPhotoLibrary.shared().performChanges({

let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
let filePath = "\(documentsPath)/\(Date().description)" + (fileType == "image" ? ".jpeg" : ".mp4")

videoData!.write(toFile: filePath, atomically: true)
if fileType == "image" {
PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: URL(fileURLWithPath: filePath))

}else {
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: URL(fileURLWithPath: filePath))

}
},
completionHandler: { success, error in

if success {

let fetchOptions = PHFetchOptions()

fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

let fetchResult = PHAsset.fetchAssets(with: fileType == "image" ? .image : .video, options: fetchOptions)

if let lastAsset = fetchResult.firstObject {
let localIdentifier = lastAsset.localIdentifier
let shareRequest = TikTokShareRequest(localIdentifiers: [localIdentifier], mediaType: fileType == "image" ? .image : .video, redirectURI: redirectUrl!)
shareRequest.shareFormat = .normal
DispatchQueue.main.async {
shareRequest.send()
result("success")
}
}
}
else if let error = error {

print(error.localizedDescription)
}
else {

result("Error getting the files!")
}
})
}

}

private func registerPlugins(registry: FlutterPluginRegistry) {
}

```

Step 3 - Create a tiktok app on tiktok [developer portal] (https://developers.tiktok.com/apps/) and get a client key and add it in info.plist acc to step 2.

Obtain the [client_key](https://developers.tiktok.com/apps/) located in the Appdetails section of your app on the TikTok for Developers website. Then add Share Kit to your app by navigating to the Manage apps page, and clicking + Add products.

<img width="862" alt="Screenshot 2023-12-06 at 09 55 38" src="https://github.com/appinioGmbH/flutter_packages/assets/58891556/9b1f4d00-96ca-4496-91e8-6aa2b5b6c992">

Your app must have access to the user's photo library to successfully share videos to TikTok.

Done ✅ - Now shareToTiktokPost will start working for IOS as well.

## Usage

```dart
Expand All @@ -236,7 +415,7 @@ class _MyAppState extends State<MyApp> {
ElevatedButton(
child: Text("ShareToWhatsapp"),
onPressed: () {
shareToWhatsApp("Message Text!!", file.getAbsolutePath());
shareToWhatsApp("Message Text!!", filePaths: [file.getAbsolutePath()]);
},
),
],
Expand All @@ -246,7 +425,7 @@ class _MyAppState extends State<MyApp> {
}
Future<void> shareToWhatsApp(String message, String filePath) async{
Future<void> shareToWhatsApp(String message, {List<String>? filePaths) async{
String response = await appinioSocialShare.shareToWhatsapp(message,filePath: filePath);
print(response);
}
Expand All @@ -262,21 +441,21 @@ class _MyAppState extends State<MyApp> {
| Method | iOS | Android | Parameters | Description
|:-------------|:-------------:|:-------------:|:-------------|:-------------
| getInstalledApps |✔️| ✔️ | - | Get a Map of all the apps with a boolean value.
| shareToWhatsapp |✔️| ✔️ | String message, {String? filePath} | Share Image and text to Whatsapp. For Ios only text works.
| shareToTelegram |✔️| ✔️ | String message, {String? filePath} | Share Image and text to Telegram. For Ios only text works.
| shareToWhatsapp |✔️| ✔️ | String message, {List<String>? filePaths} | Share Image and text to Whatsapp. For Ios only text works.
| shareToTelegram |✔️| ✔️ | String message, {List<String>? filePaths} | Share Image and text to Telegram. For Ios only text works.
| shareToInstagramDirect |✔️| ✔️ | String message | Share text message to Instagram.
| shareToInstagramFeed |✔️| ✔️ | String imagePath | Share image to Instagram feed.
| shareToInstagramReel |✔️| ✔️ | String imagePath | Share video to Instagram Reel.
| shareToInstagramFeed |✔️| ✔️ | List<String> imagePaths | Share image to Instagram feed.
| shareToInstagramReel |✔️| ✔️ | List<String> videoPaths | Share video to Instagram Reel.
| shareToInstagramStory |✔️| ✔️ | String facebookAppId, String stickerImage,{String? backgroundImage,String? backgroundVideo, String? backgroundTopColor,String? backgroundBottomColor,String? attributionURL} | Share background image, movable sticker, background colors to Instagram Story.
| shareToFacebook |✔️| ✔️ | String message, String filePath | Share text hashtag and image to Facebook.
| shareToFacebook |✔️| ✔️ | String message, List<String> filePaths | Share text hashtag and image to Facebook.
| shareToFacebookStory |✔️| ✔️ |String stickerImage,String appId,{String? backgroundImage, String? backgroundVideo, String? backgroundTopColor, String? backgroundBottomColor, String? attributionURL} | Share background image, movable sticker, background colors to Facebook Story.
| shareToMessenger |✔️| ✔️ | String message | Share text message to Messenger.
| shareToTiktokStatus |❌ | ✔️ | String filePath | ShaShare image to Tiktok Story.
| shareToTiktokStatus |❌ | ✔️ | List<String> filePaths | ShaShare image to Tiktok Story.
| shareToTiktokPost |❌ | ✔️ | String videoPath | Share video to tiktok.
| shareToTwitter | ✔️ | ✔️ | String message, {String? filePath} | Share Image and text to Twitter.
| shareToSMS |✔️| ✔️ | String message, {String? filePath} | Share Image and text to default sms app.
| shareToTwitter | ✔️ | ✔️ | String message, {List<String>? filePaths} | Share Image and text to Twitter.
| shareToSMS |✔️| ✔️ | String message, {List<String>? filePaths} | Share Image and text to default sms app.
| copyToClipBoard |✔️| ✔️ | String message | To Copy text to clipboard.
| shareToSystem |✔️| ✔️ | String title,String message, {String? filePath} | Open default System sheet, to share text and image.
| shareToSystem |✔️| ✔️ | String title,String message, {List<String>? filePaths} | Open default System sheet, to share text and image.



Expand Down
2 changes: 1 addition & 1 deletion packages/appinio_social_share/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ android {
}

dependencies {
implementation 'com.facebook.android:facebook-share:5.15.3'
implementation 'com.facebook.android:facebook-share:16.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.appinio.socialshare.appinio_social_share.utils.SocialShareUtil;

import java.util.ArrayList;
import java.util.Map;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
Expand Down Expand Up @@ -72,7 +73,7 @@ public String decideApp(@NonNull MethodCall call, @NonNull Result result) {
String title = call.argument("title");
String message = call.argument("message");
String appId = call.argument("appId");
String imagePath = call.argument("imagePath");
ArrayList<String> imagePaths = call.argument("imagePaths");
String stickerImage = call.argument("stickerImage");
String attributionURL = call.argument("attributionURL");
String backgroundImage = call.argument("backgroundImage");
Expand All @@ -86,7 +87,7 @@ public String decideApp(@NonNull MethodCall call, @NonNull Result result) {
case INSTAGRAM_DIRECT:
return socialShareUtil.shareToInstagramDirect(message,activeContext);
case INSTAGRAM_FEED:
return socialShareUtil.shareToInstagramFeed(imagePath, activeContext, message);
return socialShareUtil.shareToInstagramFeed(imagePaths, activeContext, message);
case INSTAGRAM_STORIES:
return socialShareUtil.shareToInstagramStory(appId, stickerImage, backgroundImage, backgroundTopColor, backgroundBottomColor, attributionURL, activeContext);
case FACEBOOK_STORIES:
Expand All @@ -95,22 +96,22 @@ public String decideApp(@NonNull MethodCall call, @NonNull Result result) {
return socialShareUtil.shareToMessenger(message, activeContext);
case FACEBOOK:
if (activity == null) return SocialShareUtil.UNKNOWN_ERROR;
socialShareUtil.shareToFacebook(imagePath, message, activity, result);
socialShareUtil.shareToFacebook(imagePaths, message, activity, result);
return null;
case WHATSAPP:
return socialShareUtil.shareToWhatsApp(imagePath, message, activeContext);
return socialShareUtil.shareToWhatsApp(imagePaths, message, activeContext);
case TELEGRAM:
return socialShareUtil.shareToTelegram(imagePath, activeContext, message);
return socialShareUtil.shareToTelegram(imagePaths, activeContext, message);
case TWITTER:
return socialShareUtil.shareToTwitter(imagePath, activeContext, message);
return socialShareUtil.shareToTwitter(imagePaths, activeContext, message);
case COPY_TO_CLIPBOARD:
return socialShareUtil.copyToClipBoard(message, activeContext);
case SYSTEM_SHARE:
return socialShareUtil.shareToSystem(title, message, imagePath, "image/*", title, context);
return socialShareUtil.shareToSystem(title, message, imagePaths, "image/*", title, context);
case TIKTOK:
return socialShareUtil.shareToTikTok(imagePath, activeContext, message);
return socialShareUtil.shareToTikTok(imagePaths, activeContext, message);
case SMS:
return socialShareUtil.shareToSMS(message, activeContext,imagePath);
return socialShareUtil.shareToSMS(message, activeContext,imagePaths);
default:
return null;
}
Expand Down
Loading

0 comments on commit b267516

Please sign in to comment.