Skip to content

add push service extension #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 160 additions & 1 deletion Antidote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@
9CEE6B501C528AAA00A1ECB5 /* SettingsAboutController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CEE6B4E1C528AAA00A1ECB5 /* SettingsAboutController.swift */; };
9CEE6B521C528AB600A1ECB5 /* SettingsAdvancedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CEE6B511C528AB600A1ECB5 /* SettingsAdvancedController.swift */; };
9CEE6B531C528AB600A1ECB5 /* SettingsAdvancedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CEE6B511C528AB600A1ECB5 /* SettingsAdvancedController.swift */; };
AF2C929D279AB3F10094C08D /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF2C929C279AB3F10094C08D /* NotificationService.swift */; };
AF2C92A1279AB3F10094C08D /* pushextension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = AF2C929A279AB3F10094C08D /* pushextension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
AFA023F4274C069100FBFCC0 /* ConnectionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA023F3274C069100FBFCC0 /* ConnectionStatus.swift */; };
AFA024022753CC9000FBFCC0 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = AFA024012753CC9000FBFCC0 /* GoogleService-Info.plist */; };
D4F896D05F7EAA7C321A2AA8 /* libPods-Antidote.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 034E57B3AE56E352BBAA0487 /* libPods-Antidote.a */; };
Expand Down Expand Up @@ -643,8 +645,29 @@
remoteGlobalIDString = 1164762E19794D3300DB20B8;
remoteInfo = Antidote;
};
AF2C929F279AB3F10094C08D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 1164762719794D3300DB20B8 /* Project object */;
proxyType = 1;
remoteGlobalIDString = AF2C9299279AB3F10094C08D;
remoteInfo = pushextension;
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
AF2C92A2279AB3F10094C08D /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
AF2C92A1279AB3F10094C08D /* pushextension.appex in Embed App Extensions */,
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
02404DE3D3BB1BF461C45EA0 /* Pods-ScreenshotsUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ScreenshotsUITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ScreenshotsUITests/Pods-ScreenshotsUITests.debug.xcconfig"; sourceTree = "<group>"; };
034E57B3AE56E352BBAA0487 /* libPods-Antidote.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Antidote.a"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -922,6 +945,9 @@
9CEE6B451C5289E200A1ECB5 /* SettingsMainController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsMainController.swift; sourceTree = "<group>"; };
9CEE6B4E1C528AAA00A1ECB5 /* SettingsAboutController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsAboutController.swift; sourceTree = "<group>"; };
9CEE6B511C528AB600A1ECB5 /* SettingsAdvancedController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsAdvancedController.swift; sourceTree = "<group>"; };
AF2C929A279AB3F10094C08D /* pushextension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = pushextension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
AF2C929C279AB3F10094C08D /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
AF2C929E279AB3F10094C08D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
AFA023F3274C069100FBFCC0 /* ConnectionStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionStatus.swift; sourceTree = "<group>"; };
AFA024012753CC9000FBFCC0 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
B3C17AF8CE3B4AD1B68F2B5B /* Pods-Antidote.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Antidote.release.xcconfig"; path = "Pods/Target Support Files/Pods-Antidote/Pods-Antidote.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -956,6 +982,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
AF2C9297279AB3F10094C08D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand Down Expand Up @@ -1036,6 +1069,7 @@
1164763819794D3300DB20B8 /* Antidote */,
1173F0571BC5D94400B88B7B /* AntidoteTests */,
111782A81DC64391000C1721 /* ScreenshotsUITests */,
AF2C929B279AB3F10094C08D /* pushextension */,
1164763119794D3300DB20B8 /* Frameworks */,
1164763019794D3300DB20B8 /* Products */,
1173EFB21BC5C40100B88B7B /* Submodules */,
Expand All @@ -1049,6 +1083,7 @@
1164762F19794D3300DB20B8 /* Antidote.app */,
1173F0561BC5D94400B88B7B /* AntidoteTests.xctest */,
111782A71DC64391000C1721 /* ScreenshotsUITests.xctest */,
AF2C929A279AB3F10094C08D /* pushextension.appex */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -1403,6 +1438,15 @@
name = Running;
sourceTree = "<group>";
};
AF2C929B279AB3F10094C08D /* pushextension */ = {
isa = PBXGroup;
children = (
AF2C929C279AB3F10094C08D /* NotificationService.swift */,
AF2C929E279AB3F10094C08D /* Info.plist */,
);
path = pushextension;
sourceTree = "<group>";
};
D5C4D8B82C26B8F47A461D93 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1468,10 +1512,12 @@
1164762C19794D3300DB20B8 /* Frameworks */,
1164762D19794D3300DB20B8 /* Resources */,
F334EF7D7E56B63481570925 /* [CP] Copy Pods Resources */,
AF2C92A2279AB3F10094C08D /* Embed App Extensions */,
);
buildRules = (
);
dependencies = (
AF2C92A0279AB3F10094C08D /* PBXTargetDependency */,
);
name = Antidote;
productName = Antidote;
Expand All @@ -1498,13 +1544,30 @@
productReference = 1173F0561BC5D94400B88B7B /* AntidoteTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
AF2C9299279AB3F10094C08D /* pushextension */ = {
isa = PBXNativeTarget;
buildConfigurationList = AF2C92A5279AB3F10094C08D /* Build configuration list for PBXNativeTarget "pushextension" */;
buildPhases = (
AF2C9296279AB3F10094C08D /* Sources */,
AF2C9297279AB3F10094C08D /* Frameworks */,
AF2C9298279AB3F10094C08D /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = pushextension;
productName = pushextension;
productReference = AF2C929A279AB3F10094C08D /* pushextension.appex */;
productType = "com.apple.product-type.app-extension";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
1164762719794D3300DB20B8 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastSwiftUpdateCheck = 1250;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = zoxcore;
TargetAttributes = {
Expand Down Expand Up @@ -1534,6 +1597,11 @@
};
TestTargetID = 1164762E19794D3300DB20B8;
};
AF2C9299279AB3F10094C08D = {
CreatedOnToolsVersion = 12.5;
DevelopmentTeam = Y46L589C5C;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = 1164762A19794D3300DB20B8 /* Build configuration list for PBXProject "Antidote" */;
Expand Down Expand Up @@ -1575,6 +1643,7 @@
1164762E19794D3300DB20B8 /* Antidote */,
1173F0551BC5D94400B88B7B /* AntidoteTests */,
111782A61DC64391000C1721 /* ScreenshotsUITests */,
AF2C9299279AB3F10094C08D /* pushextension */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -1688,6 +1757,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
AF2C9298279AB3F10094C08D /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -2358,6 +2434,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
AF2C9296279AB3F10094C08D /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
AF2C929D279AB3F10094C08D /* NotificationService.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
Expand All @@ -2371,6 +2455,11 @@
target = 1164762E19794D3300DB20B8 /* Antidote */;
targetProxy = 1173F05B1BC5D94400B88B7B /* PBXContainerItemProxy */;
};
AF2C92A0279AB3F10094C08D /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = AF2C9299279AB3F10094C08D /* pushextension */;
targetProxy = AF2C929F279AB3F10094C08D /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
Expand Down Expand Up @@ -2673,6 +2762,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 2D5B916CEDBEC1B69CD1EFA4 /* Pods-Antidote.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
Expand Down Expand Up @@ -2706,6 +2796,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = B3C17AF8CE3B4AD1B68F2B5B /* Pods-Antidote.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
Expand Down Expand Up @@ -2787,6 +2878,65 @@
};
name = Release;
};
AF2C92A3279AB3F10094C08D /* 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 = Y46L589C5C;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = pushextension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.zoxcore.Antidote.pushextension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
AF2C92A4279AB3F10094C08D /* 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_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = Y46L589C5C;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = pushextension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.zoxcore.Antidote.pushextension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand Down Expand Up @@ -2826,6 +2976,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
AF2C92A5279AB3F10094C08D /* Build configuration list for PBXNativeTarget "pushextension" */ = {
isa = XCConfigurationList;
buildConfigurations = (
AF2C92A3279AB3F10094C08D /* Debug */,
AF2C92A4279AB3F10094C08D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 1164762719794D3300DB20B8 /* Project object */;
Expand Down
31 changes: 31 additions & 0 deletions pushextension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>pushextension</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
</dict>
</dict>
</plist>
57 changes: 57 additions & 0 deletions pushextension/NotificationService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import UserNotifications

class NotificationService: UNNotificationServiceExtension {

static var lastRemoteNotifictionTS: Int64 = 0
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

var change: Bool = false

var diffTime = Date().millisecondsSince1970 - NotificationService.lastRemoteNotifictionTS
// print("noti:Tlast=\(NotificationService.lastRemoteNotifictionTS)")
// print("noti:Tnow=\(Date().millisecondsSince1970)")
// print("noti:Tdiff=\(diffTime)")

// check if last notification was received less than 24 seconds ago
if (diffTime < (25 * 1000)) {
// print("noti:change=true")
change = true
}

NotificationService.lastRemoteNotifictionTS = Date().millisecondsSince1970

if let bestAttemptContent = bestAttemptContent {
if (change) {
// print("noti:actually changing")
bestAttemptContent.title = "connecting ..."
}
contentHandler(bestAttemptContent)
}
}

override func serviceExtensionTimeWillExpire() {
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}

}

extension Date {
var millisecondsSince1970: Int64 {
Int64((self.timeIntervalSince1970 * 1000.0).rounded())
}

init(milliseconds: Int64) {
self = Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1000)
}
}