
主要变更: 1. 新增 ep_splash.png 作为应用启动时的展示图像。 2. 更新 Info.plist 中的应用名称和相关描述,替换为 "E-Parti"。 3. 引入 EPSignatureColorGuideView 和 EPEmotionColorStorage,支持用户选择和保存专属情绪颜色。 4. 在 AppDelegate 中集成情绪颜色引导逻辑,确保用户首次登录时能够选择专属颜色。 此更新旨在提升用户体验,增强应用的品牌识别度,并提供个性化的情绪表达功能。
233 lines
6.8 KiB
Objective-C
233 lines
6.8 KiB
Objective-C
//
|
|
// ShareProvider.m
|
|
// YuMi
|
|
//
|
|
// Created by P on 2025/3/6.
|
|
//
|
|
|
|
#import "ShareProvider.h"
|
|
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
|
|
|
@implementation ShareProvider
|
|
|
|
- (instancetype)initWithTitle:(NSString *)title
|
|
subtitle:(NSString *)subtitle
|
|
appName:(NSString *)appName
|
|
url:(NSURL *)url
|
|
image:(UIImage *)image
|
|
appIcon:(UIImage *)appIcon {
|
|
// 使用标题作为占位符
|
|
self = [super initWithPlaceholderItem:title ?: @""];
|
|
if (self) {
|
|
_title = title ?: @"";
|
|
_subtitle = subtitle ?: @"";
|
|
_appName = appName ?: @"E-Parti";
|
|
_url = url;
|
|
_image = image;
|
|
_appIcon = appIcon;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - UIActivityItemSource
|
|
|
|
// 根据不同的分享类型提供不同的内容
|
|
- (id)activityViewController:(UIActivityViewController *)activityViewController
|
|
itemForActivityType:(UIActivityType)activityType {
|
|
|
|
if (!activityType) {
|
|
// 默认返回完整信息
|
|
return [self fullShareText];
|
|
}
|
|
|
|
// 邮件分享 - 返回富文本内容
|
|
if ([activityType isEqualToString:UIActivityTypeMail]) {
|
|
return [self emailShareText];
|
|
}
|
|
|
|
// 信息/短信分享 - 返回简洁文本
|
|
if ([activityType isEqualToString:UIActivityTypeMessage]) {
|
|
return [self messageShareText];
|
|
}
|
|
|
|
// 备忘录分享 - 返回详细文本
|
|
if ([activityType containsString:@"notes"] ||
|
|
[activityType containsString:@"Notes"]) {
|
|
return [self notesShareText];
|
|
}
|
|
|
|
// 社交媒体分享 - 返回带话题标签的文本
|
|
if ([activityType isEqualToString:UIActivityTypePostToTwitter] ||
|
|
[activityType isEqualToString:UIActivityTypePostToFacebook]) {
|
|
return [self socialShareText];
|
|
}
|
|
|
|
// AirDrop - 根据有无图片决定返回内容
|
|
if ([activityType isEqualToString:UIActivityTypeAirDrop]) {
|
|
if (self.image) {
|
|
return self.image;
|
|
} else {
|
|
return self.url ?: [self fullShareText];
|
|
}
|
|
}
|
|
|
|
// 复制链接 - 只返回URL
|
|
if ([activityType isEqualToString:UIActivityTypeCopyToPasteboard]) {
|
|
return self.url.absoluteString ?: [self fullShareText];
|
|
}
|
|
|
|
// 默认返回完整文本
|
|
return [self fullShareText];
|
|
}
|
|
|
|
// 为邮件等应用提供主题
|
|
- (NSString *)activityViewController:(UIActivityViewController *)activityViewController
|
|
subjectForActivityType:(UIActivityType)activityType {
|
|
if ([activityType isEqualToString:UIActivityTypeMail]) {
|
|
return [NSString stringWithFormat:@"来自%@的分享:%@", self.appName, self.title];
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
// 指定数据类型(对图片分享很重要)
|
|
- (NSString *)activityViewController:(UIActivityViewController *)activityViewController
|
|
dataTypeIdentifierForActivityType:(UIActivityType)activityType {
|
|
|
|
if (self.image && [activityType isEqualToString:UIActivityTypeAirDrop]) {
|
|
if (@available(iOS 14.0, *)) {
|
|
return UTTypePNG.identifier;
|
|
} else {
|
|
return @"public.png";
|
|
}
|
|
}
|
|
|
|
if (@available(iOS 14.0, *)) {
|
|
return UTTypeText.identifier;
|
|
} else {
|
|
return @"public.plain-text";
|
|
}
|
|
}
|
|
|
|
// 提供链接预览元数据
|
|
- (LPLinkMetadata *)activityViewControllerLinkMetadata:(UIActivityViewController *)activityViewController {
|
|
LPLinkMetadata *metadata = [[LPLinkMetadata alloc] init];
|
|
|
|
// 设置标题
|
|
metadata.title = self.title;
|
|
|
|
// 使用 originalURL 技巧显示副标题
|
|
if (self.subtitle.length > 0) {
|
|
metadata.originalURL = [NSURL fileURLWithPath:self.subtitle];
|
|
}
|
|
|
|
// 设置实际URL
|
|
if (self.url) {
|
|
metadata.URL = self.url;
|
|
}
|
|
|
|
// 设置图标 - 优先使用应用图标,其次使用分享图片
|
|
UIImage *iconToUse = self.appIcon ?: self.image;
|
|
if (iconToUse) {
|
|
metadata.iconProvider = [[NSItemProvider alloc] initWithObject:iconToUse];
|
|
}
|
|
|
|
// 如果有图片且不同于图标,设置为预览图
|
|
if (self.image && self.image != iconToUse) {
|
|
metadata.imageProvider = [[NSItemProvider alloc] initWithObject:self.image];
|
|
}
|
|
|
|
return metadata;
|
|
}
|
|
|
|
#pragma mark - 私有方法 - 不同分享文本格式
|
|
|
|
- (NSString *)fullShareText {
|
|
NSMutableString *text = [NSMutableString string];
|
|
|
|
if (self.title.length > 0) {
|
|
[text appendFormat:@"📱 %@\n\n", self.title];
|
|
}
|
|
|
|
if (self.subtitle.length > 0) {
|
|
[text appendFormat:@"%@\n\n", self.subtitle];
|
|
}
|
|
|
|
if (self.url) {
|
|
[text appendFormat:@"🔗 %@\n\n", self.url.absoluteString];
|
|
}
|
|
|
|
[text appendFormat:@"—— 来自 %@ ——", self.appName];
|
|
|
|
return text.copy;
|
|
}
|
|
|
|
- (NSString *)emailShareText {
|
|
NSMutableString *text = [NSMutableString string];
|
|
|
|
[text appendString:@"<html><body>"];
|
|
|
|
if (self.title.length > 0) {
|
|
[text appendFormat:@"<h2>📱 %@</h2>", self.title];
|
|
}
|
|
|
|
if (self.subtitle.length > 0) {
|
|
[text appendFormat:@"<p>%@</p>", self.subtitle];
|
|
}
|
|
|
|
if (self.url) {
|
|
[text appendFormat:@"<p><a href=\"%@\">🔗 点击访问</a></p>", self.url.absoluteString];
|
|
}
|
|
|
|
[text appendFormat:@"<br><hr><small>通过 %@ 分享</small>", self.appName];
|
|
[text appendString:@"</body></html>"];
|
|
|
|
return text.copy;
|
|
}
|
|
|
|
- (NSString *)messageShareText {
|
|
if (self.url) {
|
|
return [NSString stringWithFormat:@"📱 %@\n%@", self.title, self.url.absoluteString];
|
|
}
|
|
return [NSString stringWithFormat:@"📱 %@\n%@", self.title, self.subtitle];
|
|
}
|
|
|
|
- (NSString *)notesShareText {
|
|
NSMutableString *text = [NSMutableString string];
|
|
|
|
[text appendFormat:@"📝 %@\n", self.title];
|
|
[text appendString:@"━━━━━━━━━━━━━━━━━━━━\n\n"];
|
|
|
|
if (self.subtitle.length > 0) {
|
|
[text appendFormat:@"📄 %@\n\n", self.subtitle];
|
|
}
|
|
|
|
if (self.url) {
|
|
[text appendFormat:@"🔗 链接:%@\n\n", self.url.absoluteString];
|
|
}
|
|
|
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
formatter.dateFormat = @"yyyy-MM-dd HH:mm";
|
|
[text appendFormat:@"⏰ 保存时间:%@\n", [formatter stringFromDate:[NSDate date]]];
|
|
[text appendFormat:@"📱 来源:%@", self.appName];
|
|
|
|
return text.copy;
|
|
}
|
|
|
|
- (NSString *)socialShareText {
|
|
NSMutableString *text = [NSMutableString string];
|
|
|
|
if (self.title.length > 0) {
|
|
[text appendFormat:@"📱 %@ ", self.title];
|
|
}
|
|
|
|
if (self.url) {
|
|
[text appendFormat:@"%@ ", self.url.absoluteString];
|
|
}
|
|
|
|
[text appendFormat:@"#%@ #分享 #推荐", [self.appName stringByReplacingOccurrencesOfString:@" " withString:@""]];
|
|
|
|
return text.copy;
|
|
}
|
|
|
|
@end
|