Add push notifications support and update AppDelegate

This commit is contained in:
“SamoilenkoVadym” 2025-03-03 16:10:33 +00:00
parent b5f1e06a14
commit 49638e2519
5 changed files with 79 additions and 9 deletions

View file

@ -6,6 +6,10 @@
objectVersion = 77;
objects = {
/* Begin PBXBuildFile section */
F7DA16952D76075B00FEF25A /* LocalAuthentication.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7DA16942D76075B00FEF25A /* LocalAuthentication.framework */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
F75D6AD62D75CB060073F403 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
@ -27,11 +31,25 @@
F75D6AC02D75CB050073F403 /* Coinly.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Coinly.app; sourceTree = BUILT_PRODUCTS_DIR; };
F75D6AD52D75CB060073F403 /* CoinlyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoinlyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F75D6ADF2D75CB060073F403 /* CoinlyUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoinlyUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F7DA16942D76075B00FEF25A /* LocalAuthentication.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LocalAuthentication.framework; path = System/Library/Frameworks/LocalAuthentication.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
F7DA16972D76079A00FEF25A /* Exceptions for "Coinly" folder in "Coinly" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
);
target = F75D6ABF2D75CB050073F403 /* Coinly */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
F75D6AC22D75CB050073F403 /* Coinly */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
F7DA16972D76079A00FEF25A /* Exceptions for "Coinly" folder in "Coinly" target */,
);
path = Coinly;
sourceTree = "<group>";
};
@ -52,6 +70,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F7DA16952D76075B00FEF25A /* LocalAuthentication.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -78,6 +97,7 @@
F75D6AC22D75CB050073F403 /* Coinly */,
F75D6AD82D75CB060073F403 /* CoinlyTests */,
F75D6AE22D75CB060073F403 /* CoinlyUITests */,
F7DA16932D76075A00FEF25A /* Frameworks */,
F75D6AC12D75CB050073F403 /* Products */,
);
sourceTree = "<group>";
@ -92,6 +112,14 @@
name = Products;
sourceTree = "<group>";
};
F7DA16932D76075A00FEF25A /* Frameworks */ = {
isa = PBXGroup;
children = (
F7DA16942D76075B00FEF25A /* LocalAuthentication.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -393,12 +421,15 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Coinly/Coinly.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Coinly/Preview Content\"";
DEVELOPMENT_TEAM = DQDRL8F7U2;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Coinly/Info.plist;
INFOPLIST_KEY_LSApplicationCategoryType = "";
INFOPLIST_KEY_NSFaceIDUsageDescription = "Coinly uses Face ID to securely access your financial data";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
@ -423,12 +454,15 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Coinly/Coinly.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Coinly/Preview Content\"";
DEVELOPMENT_TEAM = DQDRL8F7U2;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Coinly/Info.plist;
INFOPLIST_KEY_LSApplicationCategoryType = "";
INFOPLIST_KEY_NSFaceIDUsageDescription = "Coinly uses Face ID to securely access your financial data";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;

View file

@ -1,15 +1,8 @@
//
// AppDelegate.swift
// Coinly
//
// Created by Vadym Samoilenko on 03/03/2025.
//
import UIKit
import UserNotifications
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
@ -20,9 +13,37 @@ class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDele
// Set notification delegate
UNUserNotificationCenter.current().delegate = self
// Request notification authorization
requestNotificationPermission()
// Register for remote notifications
application.registerForRemoteNotifications()
return true
}
private func requestNotificationPermission() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
if success {
print("Notification permission granted")
} else if let error = error {
print("Error requesting notification permission: \(error.localizedDescription)")
}
}
}
// Handle successful registration of remote notifications
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
}
// Handle failed registration of remote notifications
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register for remote notifications: \(error)")
}
// MARK: - UNUserNotificationCenterDelegate
func userNotificationCenter(
_ center: UNUserNotificationCenter,
@ -40,4 +61,4 @@ class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDele
// Handle notification response
completionHandler()
}
}
}

View file

@ -0,0 +1,5 @@
<?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/>
</plist>

10
Coinly/Coinly/Info.plist Normal file
View file

@ -0,0 +1,10 @@
<?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>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
</dict>
</plist>