Skip to content

Commit

Permalink
增加下拉消息显示大图
Browse files Browse the repository at this point in the history
格式化代码;删除多余的配置文件。

\t 替换成空格

去掉多余的\t
  • Loading branch information
uuneo committed Dec 8, 2024
1 parent c7886b5 commit 80d6e22
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 7 deletions.
54 changes: 54 additions & 0 deletions Bark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@
06F11E7727D9D5FB00F00298 /* QRScannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F11E7627D9D5FB00F00298 /* QRScannerViewController.swift */; };
06FB04042C53575400F3A213 /* SharedDefines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FB04032C53575400F3A213 /* SharedDefines.swift */; };
06FB04052C53575400F3A213 /* SharedDefines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FB04032C53575400F3A213 /* SharedDefines.swift */; };
19BE8EBF2D03514A009BF080 /* ImageDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E944792C0704E500AC86AB /* ImageDownloader.swift */; };
1E73F99E2C282822002BF649 /* SectionViewController-iPad.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E73F99D2C282822002BF649 /* SectionViewController-iPad.swift */; };
1EFB545D2C314A6800B8E51B /* BarkSplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EFB545C2C314A6800B8E51B /* BarkSplitViewController.swift */; };
1EFB545F2C32514000B8E51B /* SectionViewModel-iPad.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EFB545E2C32514000B8E51B /* SectionViewModel-iPad.swift */; };
3428272069AFAFE2C683FEB0 /* libPods-Bark.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CCC722470308049D180876C7 /* libPods-Bark.a */; };
879AE4D4178855A9672009E4 /* libPods-NotificationServiceExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B7F8BDFAA047451561798F58 /* libPods-NotificationServiceExtension.a */; };
88757E3ACE0EA6A48577C958 /* libPods-NotificationContentExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6616B1ACAA7E422700D90C2B /* libPods-NotificationContentExtension.a */; };
B963F7D5BA7AC2571E71EF66 /* libPods-BarkTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 76381A752CCCD4DA6BB2A566 /* libPods-BarkTests.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -399,11 +401,14 @@
1E73F99D2C282822002BF649 /* SectionViewController-iPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SectionViewController-iPad.swift"; sourceTree = "<group>"; };
1EFB545C2C314A6800B8E51B /* BarkSplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarkSplitViewController.swift; sourceTree = "<group>"; };
1EFB545E2C32514000B8E51B /* SectionViewModel-iPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SectionViewModel-iPad.swift"; sourceTree = "<group>"; };
4A9C3B74281C8607B364CED7 /* Pods-NotificationContentExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationContentExtension.release.xcconfig"; path = "Target Support Files/Pods-NotificationContentExtension/Pods-NotificationContentExtension.release.xcconfig"; sourceTree = "<group>"; };
519481D715B40109627E1B49 /* Pods-NotificationServiceExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationServiceExtension.release.xcconfig"; path = "Target Support Files/Pods-NotificationServiceExtension/Pods-NotificationServiceExtension.release.xcconfig"; sourceTree = "<group>"; };
6616B1ACAA7E422700D90C2B /* libPods-NotificationContentExtension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-NotificationContentExtension.a"; sourceTree = BUILT_PRODUCTS_DIR; };
76381A752CCCD4DA6BB2A566 /* libPods-BarkTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BarkTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A69B47DA6DB3B168D5770B45 /* Pods-Bark.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Bark.release.xcconfig"; path = "Target Support Files/Pods-Bark/Pods-Bark.release.xcconfig"; sourceTree = "<group>"; };
B7F8BDFAA047451561798F58 /* libPods-NotificationServiceExtension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-NotificationServiceExtension.a"; sourceTree = BUILT_PRODUCTS_DIR; };
CCC722470308049D180876C7 /* libPods-Bark.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Bark.a"; sourceTree = BUILT_PRODUCTS_DIR; };
EF45D2197673129A8128ADB7 /* Pods-NotificationContentExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationContentExtension.debug.xcconfig"; path = "Target Support Files/Pods-NotificationContentExtension/Pods-NotificationContentExtension.debug.xcconfig"; sourceTree = "<group>"; };
F20815A821395CCA155806A4 /* Pods-NotificationServiceExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationServiceExtension.debug.xcconfig"; path = "Target Support Files/Pods-NotificationServiceExtension/Pods-NotificationServiceExtension.debug.xcconfig"; sourceTree = "<group>"; };
FB59D77AB30F7AD98BA72C3E /* Pods-BarkTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BarkTests.debug.xcconfig"; path = "Target Support Files/Pods-BarkTests/Pods-BarkTests.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -415,6 +420,7 @@
files = (
0632CE2020EC9098003FDF46 /* UserNotificationsUI.framework in Frameworks */,
0632CE1F20EC9098003FDF46 /* UserNotifications.framework in Frameworks */,
88757E3ACE0EA6A48577C958 /* libPods-NotificationContentExtension.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -710,6 +716,7 @@
CCC722470308049D180876C7 /* libPods-Bark.a */,
76381A752CCCD4DA6BB2A566 /* libPods-BarkTests.a */,
B7F8BDFAA047451561798F58 /* libPods-NotificationServiceExtension.a */,
6616B1ACAA7E422700D90C2B /* libPods-NotificationContentExtension.a */,
);
name = Frameworks;
sourceTree = "<group>";
Expand All @@ -723,6 +730,8 @@
121D9B1ED4E8D26F345BC5C0 /* Pods-BarkTests.release.xcconfig */,
F20815A821395CCA155806A4 /* Pods-NotificationServiceExtension.debug.xcconfig */,
519481D715B40109627E1B49 /* Pods-NotificationServiceExtension.release.xcconfig */,
EF45D2197673129A8128ADB7 /* Pods-NotificationContentExtension.debug.xcconfig */,
4A9C3B74281C8607B364CED7 /* Pods-NotificationContentExtension.release.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
Expand All @@ -734,9 +743,11 @@
isa = PBXNativeTarget;
buildConfigurationList = 0632CE2D20EC9098003FDF46 /* Build configuration list for PBXNativeTarget "NotificationContentExtension" */;
buildPhases = (
0B84A6EDEEC0D92E4E6CAFF1 /* [CP] Check Pods Manifest.lock */,
0632CE1A20EC9098003FDF46 /* Sources */,
0632CE1B20EC9098003FDF46 /* Frameworks */,
0632CE1C20EC9098003FDF46 /* Resources */,
16C0395E271EF88C500FD38B /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -990,6 +1001,46 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
0B84A6EDEEC0D92E4E6CAFF1 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-NotificationContentExtension-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
16C0395E271EF88C500FD38B /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-NotificationContentExtension/Pods-NotificationContentExtension-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/Kingfisher/Kingfisher.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Kingfisher.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-NotificationContentExtension/Pods-NotificationContentExtension-resources.sh\"\n";
showEnvVarsInLog = 0;
};
330C2B4092D535691BE03E9D /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1127,6 +1178,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
19BE8EBF2D03514A009BF080 /* ImageDownloader.swift in Sources */,
0687F2AA2CCB7FA500B2A52F /* UIFont+Extension.swift in Sources */,
0632CE2320EC9098003FDF46 /* NotificationViewController.swift in Sources */,
06BCAE572CDB19420092867A /* GroupMuteSettingManager.swift in Sources */,
Expand Down Expand Up @@ -1307,6 +1359,7 @@
/* Begin XCBuildConfiguration section */
0632CE2B20EC9098003FDF46 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = EF45D2197673129A8128ADB7 /* Pods-NotificationContentExtension.debug.xcconfig */;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = NotificationContentExtension/NotificationContentExtension.entitlements;
Expand All @@ -1329,6 +1382,7 @@
};
0632CE2C20EC9098003FDF46 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 4A9C3B74281C8607B364CED7 /* Pods-NotificationContentExtension.release.xcconfig */;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = NotificationContentExtension/NotificationContentExtension.entitlements;
Expand Down
5 changes: 5 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ target 'NotificationServiceExtension' do
pod 'SwiftyJSON'
end

target 'NotificationContentExtension' do
pod 'Kingfisher'
end


post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
Expand Down
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ SPEC CHECKSUMS:
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a

PODFILE CHECKSUM: c61d77544f2f3b62338f3ccb60fa5e617632a6c0
PODFILE CHECKSUM: f77d55c0faaaa113ec2933a6312afef56214e64c

COCOAPODS: 1.16.2
51 changes: 45 additions & 6 deletions notificationContentExtension/NotificationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
return label
}()

/// 增加图片view
let imageView: UIImageView = {
let view = UIImageView()
view.contentMode = .scaleAspectFit
return view
}()

override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(self.noticeLabel)
self.view.addSubview(self.imageView)
self.preferredContentSize = CGSize(width: 0, height: 1)
}

Expand All @@ -37,6 +45,9 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
}

func didReceive(_ notification: UNNotification) {
/// 处理图片显示
self.ImageHandler(notification)

guard notification.request.content.userInfo["autocopy"] as? String == "1"
|| notification.request.content.userInfo["automaticallycopy"] as? String == "1"
else {
Expand All @@ -59,7 +70,7 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
completion(.dismiss)
}
}

/// 复制
func copyAction(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
let userInfo = response.notification.request.content.userInfo
Expand All @@ -73,20 +84,48 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
showTips(text: NSLocalizedString("Copy", comment: ""))
completion(.doNotDismiss)
}

/// 静音分组
func muteAction(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
let groupName = response.notification.request.content.threadIdentifier
// 静音一小时
GroupMuteSettingManager().settings[groupName] = Date() + 60 * 60

showTips(text: String(format: NSLocalizedString("groupMuted", comment: ""), groupName.isEmpty ? "default" : groupName))
completion(.doNotDismiss)
}

func showTips(text: String) {
self.preferredContentSize = CGSize(width: 0, height: 40)
/// 调整页面整个大小为image的高度和label的高度总和
self.preferredContentSize = CGSize(width: 0, height: self.imageView.frame.height + 40)
self.noticeLabel.text = text
self.noticeLabel.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 40)
/// 调整 y的位置,如果复制内容,显示在图片的底部
self.noticeLabel.frame = CGRect(x: 0, y: self.imageView.frame.height, width: self.view.bounds.width, height: 40)
}
}

extension NotificationViewController {
/// 处理下拉显示大图
func ImageHandler(_ notification: UNNotification) {
Task {
guard let imageUrl = notification.request.content.userInfo["image"] as? String,
let imageFileUrl = await ImageDownloader.downloadImage(imageUrl),
let image = UIImage(contentsOfFile: imageFileUrl)
else {
self.imageView.frame = .zero
return
}
/// 计算图片的比例按照通知界面缩放
let viewWidth = view.bounds.size.width
let aspectRatio = image.size.width / image.size.height
let viewHeight = viewWidth / aspectRatio
let size = CGSize(width: viewWidth, height: viewHeight)

DispatchQueue.main.async {
self.preferredContentSize = size
self.imageView.image = image
self.imageView.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
}
}
}
}

0 comments on commit 80d6e22

Please sign in to comment.