Commit 23d81783 by ludi

修复兼容推特

parent d0471c88
...@@ -324,25 +324,62 @@ ...@@ -324,25 +324,62 @@
self.shareSuccess = success; self.shareSuccess = success;
self.shareFailure = failure; self.shareFailure = failure;
UIViewController *presentingViewController = viewController ?: [UIViewController fus_topViewController];
if (viewController == nil || ![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]]) { if (presentingViewController == nil) {
[FUSDialogView fus_showDialog:[NSString fus_localString:@"请先安装Twitter"]]; if (self.shareFailure) {
if(self.shareFailure)_shareFailure(); self.shareFailure();
}
self.shareSuccess = nil; self.shareSuccess = nil;
self.shareFailure = nil; self.shareFailure = nil;
return; return;
} }
// 检查 Twitter 是否可用 BOOL canOpenTwitter = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]];
if (![SLComposeViewController isAvailableForServiceType:@"com.apple.share.Twitter.post"]) { BOOL isTwitterServiceAvailable = [SLComposeViewController isAvailableForServiceType:@"com.apple.share.Twitter.post"];
[FUSDialogView fus_showDialog:[NSString fus_localString:@"请先安装Twitter"]]; if (!canOpenTwitter || !isTwitterServiceAvailable) {
if(self.shareFailure)_shareFailure(); [self fus_presentTwitterIntentWithContentURL:contentURL
self.shareSuccess = nil; content:content
self.shareFailure = nil; image:image
shareType:shareType
completion:^(BOOL openSuccess) {
if (openSuccess) {
self.shareSuccess = nil;
self.shareFailure = nil;
return;
}
[self fus_presentTwitterFallbackActivityViewControllerWithContentURL:contentURL
content:content
image:image
from:from
roomId:roomId
shareType:shareType
viewController:presentingViewController];
}];
return; return;
} }
SLComposeViewController *twitterComposeVC = [SLComposeViewController composeViewControllerForServiceType:@"com.apple.share.Twitter.post"]; SLComposeViewController *twitterComposeVC = [SLComposeViewController composeViewControllerForServiceType:@"com.apple.share.Twitter.post"];
if (twitterComposeVC == nil) {
[self fus_presentTwitterIntentWithContentURL:contentURL
content:content
image:image
shareType:shareType
completion:^(BOOL openSuccess) {
if (openSuccess) {
self.shareSuccess = nil;
self.shareFailure = nil;
return;
}
[self fus_presentTwitterFallbackActivityViewControllerWithContentURL:contentURL
content:content
image:image
from:from
roomId:roomId
shareType:shareType
viewController:presentingViewController];
}];
return;
}
switch (shareType) { switch (shareType) {
case FUSShareTypeText:{ case FUSShareTypeText:{
...@@ -391,7 +428,7 @@ ...@@ -391,7 +428,7 @@
}; };
twitterComposeVC.modalPresentationStyle = UIModalPresentationPageSheet; twitterComposeVC.modalPresentationStyle = UIModalPresentationPageSheet;
[[UIViewController fus_topViewController] presentViewController:twitterComposeVC animated:YES completion:^{ [presentingViewController presentViewController:twitterComposeVC animated:YES completion:^{
}]; }];
...@@ -486,6 +523,203 @@ ...@@ -486,6 +523,203 @@
// } // }
} }
/**
Twitter 分享不可用时,先尝试跳转到 X Web Intent
@param contentURL 分享链接
@param content 分享文案
@param image 分享图片
@param shareType 分享类型
@param completion 跳转完成回调
*/
- (void)fus_presentTwitterIntentWithContentURL:(NSString *)contentURL
content:(NSString *)content
image:(UIImage *)image
shareType:(FUSShareType)shareType
completion:(void(^)(BOOL openSuccess))completion{
NSString *text = content.length ? content : nil;
NSString *urlString = contentURL.length ? contentURL : nil;
switch (shareType) {
case FUSShareTypeImage:
{
if (urlString.length == 0 && text.length == 0 && image != nil) {
if (completion) {
completion(NO);
}
return;
}
}
break;
case FUSShareTypeWebUrl:
{
}
break;
case FUSShareTypeText:
case FUSShareTypeDefault:
case FUSShareTypeImageWithText:
{
}
break;
default:
break;
}
if (text.length == 0 && urlString.length == 0) {
if (completion) {
completion(NO);
}
return;
}
NSURLComponents *components = [[NSURLComponents alloc] init];
components.scheme = @"https";
components.host = @"x.com";
components.path = @"/intent/tweet";
NSMutableArray<NSURLQueryItem *> *queryItems = [NSMutableArray array];
if (text.length) {
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"text" value:text]];
}
if (urlString.length) {
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"url" value:urlString]];
}
components.queryItems = queryItems;
NSURL *intentURL = components.URL;
if (intentURL == nil) {
if (completion) {
completion(NO);
}
return;
}
[[UIApplication sharedApplication] openURL:intentURL options:@{} completionHandler:^(BOOL success) {
if (completion) {
completion(success);
}
}];
}
/**
Twitter 分享不可用且 X Web Intent 无法跳转时,降级为系统分享面板
@param contentURL 分享链接
@param content 分享文案
@param image 分享图片
@param from 分享来源
@param roomId 房间 ID
@param shareType 分享类型
@param viewController 用于弹出系统分享面板的控制器
*/
- (void)fus_presentTwitterFallbackActivityViewControllerWithContentURL:(NSString *)contentURL
content:(NSString *)content
image:(UIImage *)image
from:(FUSFrom)from
roomId:(NSString *)roomId
shareType:(FUSShareType)shareType
viewController:(UIViewController *)viewController{
NSMutableArray *activityItems = [NSMutableArray array];
NSURL *shareURL = contentURL.length ? [NSURL URLWithString:contentURL] : nil;
switch (shareType) {
case FUSShareTypeText:
{
if (content.length) {
[activityItems addObject:content];
}
}
break;
case FUSShareTypeImage:
{
if (image != nil) {
[activityItems addObject:image];
}
}
break;
case FUSShareTypeWebUrl:
{
if (content.length) {
[activityItems addObject:content];
}
if (shareURL != nil) {
[activityItems addObject:shareURL];
}
}
break;
case FUSShareTypeDefault:
case FUSShareTypeImageWithText:
{
if (image != nil) {
[activityItems addObject:image];
}
if (content.length) {
[activityItems addObject:content];
}
}
break;
default:
break;
}
if (activityItems.count == 0) {
if (content.length) {
[activityItems addObject:content];
}
if (shareURL != nil) {
[activityItems addObject:shareURL];
}
if (image != nil) {
[activityItems addObject:image];
}
}
if (activityItems.count == 0) {
[FUSDialogView fus_showDialog:[NSString fus_versionLocalString:@"暂无可分享内容"]];
if (self.shareFailure) {
self.shareFailure();
}
self.shareSuccess = nil;
self.shareFailure = nil;
return;
}
__weak typeof(self) weakSelf = self;
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (activityError != nil) {
[FUSDialogView fus_showDialog:[NSString fus_localString:@"分享失败"]];
if (weakSelf.shareFailure) {
weakSelf.shareFailure();
}
} else if (!completed) {
[FUSDialogView fus_showDialog:[NSString fus_localString:@"分享取消"]];
if (weakSelf.shareFailure) {
weakSelf.shareFailure();
}
} else {
NSString *version = [[FUSDeviceHelper getAppVersionNumber] description];
[FUSCommonHttpRequest fus_socialShareStatisticWithMode:weakSelf.mode modeType:2 version:version from:from roomId:roomId];
[FUSDialogView fus_showDialog:[NSString fus_localString:@"分享成功"]];
if (weakSelf.shareSuccess) {
weakSelf.shareSuccess();
}
}
weakSelf.shareSuccess = nil;
weakSelf.shareFailure = nil;
};
UIPopoverPresentationController *popoverController = activityViewController.popoverPresentationController;
if (popoverController != nil) {
popoverController.sourceView = viewController.view;
popoverController.sourceRect = CGRectMake(CGRectGetMidX(viewController.view.bounds), CGRectGetMidY(viewController.view.bounds), 1.0, 1.0);
}
[viewController presentViewController:activityViewController animated:YES completion:nil];
}
/* /*
line 分享 line 分享
*/ */
......
...@@ -691,7 +691,7 @@ ...@@ -691,7 +691,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements; CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20260547; CURRENT_PROJECT_VERSION = 20260548;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6GG26BHUMC; DEVELOPMENT_TEAM = 6GG26BHUMC;
ENABLE_ON_DEMAND_RESOURCES = NO; ENABLE_ON_DEMAND_RESOURCES = NO;
...@@ -956,7 +956,7 @@ ...@@ -956,7 +956,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements; CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20260547; CURRENT_PROJECT_VERSION = 20260548;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6GG26BHUMC; DEVELOPMENT_TEAM = 6GG26BHUMC;
ENABLE_ON_DEMAND_RESOURCES = NO; ENABLE_ON_DEMAND_RESOURCES = NO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment