diff --git a/Bark.xcodeproj/project.pbxproj b/Bark.xcodeproj/project.pbxproj index a86649b..6daa407 100644 --- a/Bark.xcodeproj/project.pbxproj +++ b/Bark.xcodeproj/project.pbxproj @@ -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 */ @@ -399,11 +401,14 @@ 1E73F99D2C282822002BF649 /* SectionViewController-iPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SectionViewController-iPad.swift"; sourceTree = ""; }; 1EFB545C2C314A6800B8E51B /* BarkSplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarkSplitViewController.swift; sourceTree = ""; }; 1EFB545E2C32514000B8E51B /* SectionViewModel-iPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SectionViewModel-iPad.swift"; sourceTree = ""; }; + 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 = ""; }; 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 = ""; }; + 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 = ""; }; 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 = ""; }; 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 = ""; }; 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 = ""; }; /* End PBXFileReference section */ @@ -415,6 +420,7 @@ files = ( 0632CE2020EC9098003FDF46 /* UserNotificationsUI.framework in Frameworks */, 0632CE1F20EC9098003FDF46 /* UserNotifications.framework in Frameworks */, + 88757E3ACE0EA6A48577C958 /* libPods-NotificationContentExtension.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -710,6 +716,7 @@ CCC722470308049D180876C7 /* libPods-Bark.a */, 76381A752CCCD4DA6BB2A566 /* libPods-BarkTests.a */, B7F8BDFAA047451561798F58 /* libPods-NotificationServiceExtension.a */, + 6616B1ACAA7E422700D90C2B /* libPods-NotificationContentExtension.a */, ); name = Frameworks; sourceTree = ""; @@ -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 = ""; @@ -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 = ( ); @@ -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; @@ -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 */, @@ -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; @@ -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; diff --git a/Podfile b/Podfile index e08e67c..f6a9aaf 100644 --- a/Podfile +++ b/Podfile @@ -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| diff --git a/Podfile.lock b/Podfile.lock index 93d16e4..a521dac 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -153,6 +153,6 @@ SPEC CHECKSUMS: SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a -PODFILE CHECKSUM: c61d77544f2f3b62338f3ccb60fa5e617632a6c0 +PODFILE CHECKSUM: f77d55c0faaaa113ec2933a6312afef56214e64c COCOAPODS: 1.16.2 diff --git a/notificationContentExtension/NotificationViewController.swift b/notificationContentExtension/NotificationViewController.swift index 15583d6..3888453 100644 --- a/notificationContentExtension/NotificationViewController.swift +++ b/notificationContentExtension/NotificationViewController.swift @@ -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) } @@ -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 { @@ -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 @@ -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) + } + } } }