appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
187 stars 214 forks source link

[ BUG ] : Share to Instagram Direct works on Android and iOS, but Stories do not on iOS #259

Closed lisovyk closed 5 months ago

lisovyk commented 5 months ago

Plugin name Appinio social share

Describe the bug I encountered a bug where my test users on ios can't share to instagram stories while the share-to-direct is present.

To Reproduce Steps to reproduce the behavior: I don't have an iOS physical device and it's not possible to install apps on simulator - thanks apple - so no way to create a reproducable example for me.

Expected behavior Instagram Story share works both on Android and iOS. Surprisingly, facebook stories share works fine!

Screenshots android and ios screenshots, same app version:

Screenshot 2024-03-26 at 16 44 03

2024-03-26 16 44 07

Smartphone (please complete the following information):

Additional context Here are parts of the code I am using, if it will be of any help. Thanks.

FutureBuilder(
                          future: AppinioSocialShare().getInstalledApps(),
                          builder: (context, snapshot) {
                            if (snapshot.connectionState == ConnectionState.waiting) {
                              return const Center(child: CircularProgressIndicator());
                            }
                            if (snapshot.hasError) {
                              return Center(
                                child: Text('Помилка: ${snapshot.error}'),
                              );
                            }

                            List<SharePlatform> sharePlatformsFiltered = [];
                            if (snapshot.data != null && snapshot.data!.isNotEmpty) {
                              print(snapshot.data!.entries);
                              // print all entries values
                              print(snapshot.data!.entries.map((e) => e.value).toList());
                              final installedShareApps = snapshot.data!.entries.where((e) => e.value).map((e) => e.key).toList();
                              sharePlatformsFiltered =
                                  SharePlatform.defaults.where((e) => installedShareApps.contains(e.platform_name)).toList();
                            }

                            return _buildShareOptionsGrid(theme, sharePlatformsFiltered, context);
                          },
SingleChildScrollView _buildShareOptionsGrid(ThemeData theme, List<SharePlatform> sharePlatformsFiltered, BuildContext context) {
    return SingleChildScrollView(
      child: GridView.count(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        crossAxisCount: 4,
        childAspectRatio: 1,
        children: [
          _buildCell(
            theme,
            Remix.links_line,
            'Скопіювати посилання',
            onTap: () {
              Clipboard.setData(ClipboardData(text: url));
              if (Platform.isIOS) {
                snackbarKey.currentState?.showSnackBar(const SnackBar(content: Text('Посилання скопійовано')));
              }
            },
          ),
          ...sharePlatformsFiltered
              .map(
                (SharePlatform e) => _buildCell(
                  theme,
                  e.icon,
                  e.name,
                  onTap: () async {
                    if (e.platform_name == SharePlatform.telegram.platform_name) {
                      File file = await generatePicture(context, theme, background: true);
                      AppinioSocialShare().shareToTelegram('Посилання: $url', filePaths: [file.path]);
                      // AppinioSocialShare().shareToTelegram(url);
                      // https://core.telegram.org/widgets/share
                    } else if (e.platform_name == SharePlatform.instagram_story.platform_name) {
                      File file = await generatePicture(context, theme);
                      await AppinioSocialShare().shareToInstagramStory(FACEBOOK_APP_ID,
                          stickerImage: file.path,
                          backgroundBottomColor: '#${backgroundBottomColor.value.toRadixString(16)}',
                          backgroundTopColor: '#${backgroundTopColor.value.toRadixString(16)}',
                          attributionURL: url);
                    } else if (e.platform_name == SharePlatform.instagram_direct.platform_name) {
                      await AppinioSocialShare().shareToInstagramDirect(url);
                    } else if (e.platform_name == SharePlatform.facebook_messenger.platform_name) {
                      await AppinioSocialShare().shareToMessenger(url);
                    } else if (e.platform_name == SharePlatform.facebook_story.platform_name) {
                      File file = await generatePicture(context, theme);
                      await AppinioSocialShare().shareToFacebookStory(
                        FACEBOOK_APP_ID,
                        backgroundBottomColor: '#${backgroundBottomColor.value.toRadixString(16)}',
                        backgroundTopColor: '#${backgroundTopColor.value.toRadixString(16)}',
                        stickerImage: file.path,
                        attributionURL: url,
                      );
                    } else if (e.platform_name == SharePlatform.twitter.platform_name) {
                      File file = await generatePicture(context, theme, background: true);
                      await AppinioSocialShare().shareToTwitter(
                        url,
                        filePaths: [file.path],
                      );
                    } else if (e.platform_name == SharePlatform.whatsapp.platform_name) {
                      File file = await generatePicture(context, theme, background: true);
                      await AppinioSocialShare().shareToWhatsapp(
                        url,
                        filePaths: [file.path],
                      );
                    }
                  },
                ),
              )
              .toList(),
          _buildCell(theme, Remix.more_line, 'Більше', onTap: () => Share.share(url)),
        ],
      ),
class SharePlatform {
  const SharePlatform({
    required this.name,
    required this.platform_name,
    required this.icon,
  });
  final String name;
  final String platform_name;
  final IconData icon;

  static SharePlatform get telegram => const SharePlatform(
        name: 'Телеграм',
        platform_name: 'telegram',
        icon: Remix.telegram_line,
      );

  // facebook messenger
  static SharePlatform get facebook_messenger => const SharePlatform(
        name: 'Messenger',
        platform_name: 'messenger',
        icon: Remix.messenger_line,
      );
  static SharePlatform get facebook_story => const SharePlatform(
        name: 'Історії',
        platform_name: 'facebook_stories',
        icon: Remix.messenger_line,
      );
  // whatsapp
  static SharePlatform get whatsapp => const SharePlatform(
        name: 'WhatsApp',
        platform_name: 'whatsapp',
        icon: Remix.whatsapp_line,
      );

  static SharePlatform get instagram_story => const SharePlatform(
        name: 'Історії',
        platform_name: 'instagram_stories',
        icon: Remix.instagram_line,
      );

  static SharePlatform get instagram_direct => const SharePlatform(
        name: 'Повідомлення',
        platform_name: 'instagram',
        icon: Remix.instagram_line,
      );

  static SharePlatform get twitter => const SharePlatform(
        name: 'Twitter',
        platform_name: 'twitter',
        icon: Remix.twitter_line,
      );

  static List<SharePlatform> get defaults => <SharePlatform>[
        telegram,
        instagram_story,
        instagram_direct,
        facebook_messenger,
        facebook_story,
        twitter,
        whatsapp,
      ];
}
lisovyk commented 5 months ago

additional info: stories are not available on user device, while direct is OK.

Can you hint me on how to fix it? Calling AppinioSocialShare().shareToInstagramStory() directly on ios does not work either.

Screenshot 2024-03-29 at 17 14 58
lisovyk commented 5 months ago

Fixed by adding <string>instagram-stories</string> to LSApplicationQueriesSchemes, which is missing from readme. Please update for future developers!

edit: with this fix the stories do launch, but the background colors are not passed to instagram and are not shown. well, fighting it further..

edit2: need to pass colors without transparency for it to work on ios.

lisovyk commented 5 months ago

@bilalhamud Hello! There is no <string>instagram-stories</string> addition to readme in this MR, you should probably reopen this one.

junddao commented 3 months ago

@lisovyk Can you open instagram story on android when use this package?

In my case, have error with under log....

No Activity found to handle Intent { act=com.instagram.share.ADD_TO_STORY dat=content://com.twosun.dingdongu.staging.provider/... flg=0x10000001 (has extras) }

lisovyk commented 3 months ago

Did you add the line from my comment?