From ebd483ee5880131d6602e63ca46cfa49caef2983 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 18 Oct 2018 23:09:39 +0300 Subject: Avatars in notifications --- Juick.xcodeproj/project.pbxproj | 163 +++++++++++++++++++++ .../xcschemes/xcschememanagement.plist | 5 + JuickPush/Info.plist | 31 ++++ JuickPush/NotificationService.h | 13 ++ JuickPush/NotificationService.m | 46 ++++++ 5 files changed, 258 insertions(+) create mode 100644 JuickPush/Info.plist create mode 100644 JuickPush/NotificationService.h create mode 100644 JuickPush/NotificationService.m diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index f06323d..f5d9575 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -34,6 +34,8 @@ 774528C21F930C06004D110B /* Attachment.m in Sources */ = {isa = PBXBuildFile; fileRef = 774528C11F930C06004D110B /* Attachment.m */; }; 7761133821766A3000D350CD /* ContentLoadingCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7761133621766A3000D350CD /* ContentLoadingCell.m */; }; 7761133921766A3000D350CD /* ContentLoadingCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7761133721766A3000D350CD /* ContentLoadingCell.xib */; }; + 7761135921790B0300D350CD /* NotificationService.m in Sources */ = {isa = PBXBuildFile; fileRef = 7761135821790B0300D350CD /* NotificationService.m */; }; + 7761135D21790B0300D350CD /* JuickPush.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 7761135521790B0200D350CD /* JuickPush.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 776C41BD1FD3EF180063B82E /* MessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 776C41BB1FD3EF180063B82E /* MessageCell.m */; }; 776C41BE1FD3EF180063B82E /* MessageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 776C41BC1FD3EF180063B82E /* MessageCell.xib */; }; 776C41C11FD3FF6E0063B82E /* DiscoverViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 776C41C01FD3FF6E0063B82E /* DiscoverViewController.m */; }; @@ -57,6 +59,30 @@ 77FCADDF1D6A50DA00CBA649 /* APIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 77FCADDE1D6A50DA00CBA649 /* APIClient.m */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 7761135B21790B0300D350CD /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 77317BA0181BBE8500D60005 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 7761135421790B0200D350CD; + remoteInfo = JuickPush; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 7761136121790B0300D350CD /* Embed App Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + 7761135D21790B0300D350CD /* JuickPush.appex in Embed App Extensions */, + ); + name = "Embed App Extensions"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 22EE2B61A53B73723D255877 /* libPods-Juick.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Juick.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 770A428F1E8881CB000B206A /* DeviceRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceRegistration.h; sourceTree = ""; }; @@ -102,6 +128,11 @@ 7761133521766A3000D350CD /* ContentLoadingCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentLoadingCell.h; sourceTree = ""; }; 7761133621766A3000D350CD /* ContentLoadingCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContentLoadingCell.m; sourceTree = ""; }; 7761133721766A3000D350CD /* ContentLoadingCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ContentLoadingCell.xib; sourceTree = ""; }; + 7761135521790B0200D350CD /* JuickPush.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = JuickPush.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + 7761135721790B0300D350CD /* NotificationService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NotificationService.h; sourceTree = ""; }; + 7761135821790B0300D350CD /* NotificationService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NotificationService.m; sourceTree = ""; }; + 7761135A21790B0300D350CD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7761136821790C2D00D350CD /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; }; 776C41BA1FD3EF180063B82E /* MessageCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MessageCell.h; sourceTree = ""; }; 776C41BB1FD3EF180063B82E /* MessageCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MessageCell.m; sourceTree = ""; }; 776C41BC1FD3EF180063B82E /* MessageCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageCell.xib; sourceTree = ""; }; @@ -158,12 +189,20 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7761135221790B0200D350CD /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 77317B9F181BBE8500D60005 = { isa = PBXGroup; children = ( + 7761135621790B0300D350CD /* JuickPush */, 77317BAA181BBE8500D60005 /* Frameworks */, 77317BB1181BBE8500D60005 /* Juick */, 77317BA9181BBE8500D60005 /* Products */, @@ -175,6 +214,7 @@ isa = PBXGroup; children = ( 77317BA8181BBE8500D60005 /* Juick.app */, + 7761135521790B0200D350CD /* JuickPush.appex */, ); name = Products; sourceTree = ""; @@ -193,6 +233,7 @@ 77317BAD181BBE8500D60005 /* CoreGraphics.framework */, 77317BAF181BBE8500D60005 /* UIKit.framework */, 22EE2B61A53B73723D255877 /* libPods-Juick.a */, + 7761136821790C2D00D350CD /* UserNotificationsUI.framework */, ); name = Frameworks; sourceTree = ""; @@ -284,6 +325,16 @@ path = Helpers; sourceTree = ""; }; + 7761135621790B0300D350CD /* JuickPush */ = { + isa = PBXGroup; + children = ( + 7761135721790B0300D350CD /* NotificationService.h */, + 7761135821790B0300D350CD /* NotificationService.m */, + 7761135A21790B0300D350CD /* Info.plist */, + ); + path = JuickPush; + sourceTree = ""; + }; 77FFC0151D5FD13C003BD81A /* Views */ = { isa = PBXGroup; children = ( @@ -332,16 +383,35 @@ 77317BA5181BBE8500D60005 /* Frameworks */, 77317BA6181BBE8500D60005 /* Resources */, 6F2FFD38EF490A735BDA88E5 /* [CP] Copy Pods Resources */, + 7761136121790B0300D350CD /* Embed App Extensions */, ); buildRules = ( ); dependencies = ( + 7761135C21790B0300D350CD /* PBXTargetDependency */, ); name = Juick; productName = Juick; productReference = 77317BA8181BBE8500D60005 /* Juick.app */; productType = "com.apple.product-type.application"; }; + 7761135421790B0200D350CD /* JuickPush */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7761136021790B0300D350CD /* Build configuration list for PBXNativeTarget "JuickPush" */; + buildPhases = ( + 7761135121790B0200D350CD /* Sources */, + 7761135221790B0200D350CD /* Frameworks */, + 7761135321790B0200D350CD /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = JuickPush; + productName = JuickPush; + productReference = 7761135521790B0200D350CD /* JuickPush.appex */; + productType = "com.apple.product-type.app-extension"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -362,6 +432,11 @@ }; }; }; + 7761135421790B0200D350CD = { + CreatedOnToolsVersion = 10.0; + DevelopmentTeam = KH4MX79ZK7; + ProvisioningStyle = Automatic; + }; }; }; buildConfigurationList = 77317BA3181BBE8500D60005 /* Build configuration list for PBXProject "Juick" */; @@ -378,6 +453,7 @@ projectRoot = ""; targets = ( 77317BA7181BBE8500D60005 /* Juick */, + 7761135421790B0200D350CD /* JuickPush */, ); }; /* End PBXProject section */ @@ -404,6 +480,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7761135321790B0200D350CD /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -484,8 +567,24 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7761135121790B0200D350CD /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7761135921790B0300D350CD /* NotificationService.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 7761135C21790B0300D350CD /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 7761135421790B0200D350CD /* JuickPush */; + targetProxy = 7761135B21790B0300D350CD /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ 77317BB4181BBE8500D60005 /* InfoPlist.strings */ = { isa = PBXVariantGroup; @@ -642,6 +741,61 @@ }; name = Release; }; + 7761135E21790B0300D350CD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = KH4MX79ZK7; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = JuickPush/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.juick.Juick.JuickPush; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 7761135F21790B0300D350CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = JuickPush/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.juick.Juick.JuickPush; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -663,6 +817,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 7761136021790B0300D350CD /* Build configuration list for PBXNativeTarget "JuickPush" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7761135E21790B0300D350CD /* Debug */, + 7761135F21790B0300D350CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 77317BA0181BBE8500D60005 /* Project object */; diff --git a/Juick.xcodeproj/xcuserdata/vt.xcuserdatad/xcschemes/xcschememanagement.plist b/Juick.xcodeproj/xcuserdata/vt.xcuserdatad/xcschemes/xcschememanagement.plist index 52d2f29..1d35997 100644 --- a/Juick.xcodeproj/xcuserdata/vt.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Juick.xcodeproj/xcuserdata/vt.xcuserdatad/xcschemes/xcschememanagement.plist @@ -9,6 +9,11 @@ orderHint 0 + JuickPush.xcscheme + + orderHint + 13 + SuppressBuildableAutocreation diff --git a/JuickPush/Info.plist b/JuickPush/Info.plist new file mode 100644 index 0000000..935f4fa --- /dev/null +++ b/JuickPush/Info.plist @@ -0,0 +1,31 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + JuickPush + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSExtension + + NSExtensionPointIdentifier + com.apple.usernotifications.service + NSExtensionPrincipalClass + NotificationService + + + diff --git a/JuickPush/NotificationService.h b/JuickPush/NotificationService.h new file mode 100644 index 0000000..91ca27a --- /dev/null +++ b/JuickPush/NotificationService.h @@ -0,0 +1,13 @@ +// +// NotificationService.h +// JuickPush +// +// Created by Vitaly Takmazov on 18/10/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import + +@interface NotificationService : UNNotificationServiceExtension + +@end diff --git a/JuickPush/NotificationService.m b/JuickPush/NotificationService.m new file mode 100644 index 0000000..82dead8 --- /dev/null +++ b/JuickPush/NotificationService.m @@ -0,0 +1,46 @@ +// +// NotificationService.m +// JuickPush +// +// Created by Vitaly Takmazov on 18/10/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import "NotificationService.h" + +@interface NotificationService () + +@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver); +@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent; + +@end + +@implementation NotificationService + +- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { + self.contentHandler = contentHandler; + self.bestAttemptContent = [request.content mutableCopy]; + + NSURL *avatarURL = [NSURL URLWithString:request.content.userInfo[@"avatarUrl"]]; + + NSURLSession * downloadSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; + + [[downloadSession downloadTaskWithURL:avatarURL completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) { + if (!error) { + NSError *err = nil; + NSString *temporaryDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:[response suggestedFilename]]; + [[NSFileManager defaultManager] moveItemAtPath:location.path toPath:temporaryDirectory error:&err]; + UNNotificationAttachment *avatarAttachment = [UNNotificationAttachment attachmentWithIdentifier:avatarURL.lastPathComponent URL:[NSURL fileURLWithPath:temporaryDirectory] options:nil error:&err]; + self.bestAttemptContent.attachments = @[avatarAttachment]; + self.contentHandler(self.bestAttemptContent); + } + }] resume]; +} + +- (void)serviceExtensionTimeWillExpire { + // Called just before the extension will be terminated by the system. + // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. + self.contentHandler(self.bestAttemptContent); +} + +@end -- cgit v1.2.3