From f16d75b983a011ea60c596afe01d067870970ca7 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Thu, 5 Aug 2021 15:54:04 -0400 Subject: [PATCH] Adding application state (#123) --- Config/Version.xcconfig | 2 +- .../iOS/WindowsAzureMessaging/.jazzy.yaml | 2 +- .../macOS/WindowsAzureMessaging/.jazzy.yaml | 2 +- .../tvOS/WindowsAzureMessaging/.jazzy.yaml | 2 +- Package.swift | 2 +- Package@swift-5.3.swift | 2 +- .../project.pbxproj | 16 ++++++++ .../Internal/ANHApplicationProvider.h | 37 +++++++++++++++++++ .../Internal/ANHApplicationProvider.m | 35 ++++++++++++++++++ .../WindowsAzureMessaging/MSNotificationHub.m | 8 ++-- 10 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 WindowsAzureMessaging/WindowsAzureMessaging/Internal/ANHApplicationProvider.h create mode 100644 WindowsAzureMessaging/WindowsAzureMessaging/Internal/ANHApplicationProvider.m diff --git a/Config/Version.xcconfig b/Config/Version.xcconfig index 26efd1d..c1c9a5e 100644 --- a/Config/Version.xcconfig +++ b/Config/Version.xcconfig @@ -1,2 +1,2 @@ BUILD_NUMBER = 1 -VERSION_STRING = 3.1.4 +VERSION_STRING = 3.1.5 diff --git a/Documentation/iOS/WindowsAzureMessaging/.jazzy.yaml b/Documentation/iOS/WindowsAzureMessaging/.jazzy.yaml index 7136b67..fb3d649 100644 --- a/Documentation/iOS/WindowsAzureMessaging/.jazzy.yaml +++ b/Documentation/iOS/WindowsAzureMessaging/.jazzy.yaml @@ -5,7 +5,7 @@ sdk: iphonesimulator theme: ../../Themes/apple module: WindowsAzureMessaging -module_version: 3.1.4 +module_version: 3.1.5 author: Microsoft Corp author_url: http://www.microsoft.com diff --git a/Documentation/macOS/WindowsAzureMessaging/.jazzy.yaml b/Documentation/macOS/WindowsAzureMessaging/.jazzy.yaml index 865da66..5a8ef9d 100644 --- a/Documentation/macOS/WindowsAzureMessaging/.jazzy.yaml +++ b/Documentation/macOS/WindowsAzureMessaging/.jazzy.yaml @@ -5,7 +5,7 @@ sdk: macosx theme: ../../Themes/apple module: WindowsAzureMessaging -module_version: 3.1.4 +module_version: 3.1.5 author: Microsoft Corp author_url: http://www.microsoft.com diff --git a/Documentation/tvOS/WindowsAzureMessaging/.jazzy.yaml b/Documentation/tvOS/WindowsAzureMessaging/.jazzy.yaml index 19a1f0d..d4dded5 100644 --- a/Documentation/tvOS/WindowsAzureMessaging/.jazzy.yaml +++ b/Documentation/tvOS/WindowsAzureMessaging/.jazzy.yaml @@ -5,7 +5,7 @@ sdk: appletvsimulator theme: ../../Themes/apple module: WindowsAzureMessaging -module_version: 3.1.4 +module_version: 3.1.5 author: Microsoft Corp author_url: http://www.microsoft.com diff --git a/Package.swift b/Package.swift index 2c960cc..db18241 100644 --- a/Package.swift +++ b/Package.swift @@ -24,7 +24,7 @@ let package = Package( path: "WindowsAzureMessaging/WindowsAzureMessaging", exclude: ["Support"], cSettings: [ - .define("NH_C_VERSION", to:"\"3.1.4\""), + .define("NH_C_VERSION", to:"\"3.1.5\""), .define("NH_C_BUILD", to:"\"1\""), .headerSearchPath("**"), ], diff --git a/Package@swift-5.3.swift b/Package@swift-5.3.swift index 75876de..92351ea 100644 --- a/Package@swift-5.3.swift +++ b/Package@swift-5.3.swift @@ -25,7 +25,7 @@ let package = Package( path: "WindowsAzureMessaging/WindowsAzureMessaging", exclude: ["Support"], cSettings: [ - .define("NH_C_VERSION", to:"\"3.1.4\""), + .define("NH_C_VERSION", to:"\"3.1.5\""), .define("NH_C_BUILD", to:"\"1\""), .headerSearchPath("**"), ], diff --git a/WindowsAzureMessaging/WindowsAzureMessaging.xcodeproj/project.pbxproj b/WindowsAzureMessaging/WindowsAzureMessaging.xcodeproj/project.pbxproj index ba1dfe4..464aee7 100644 --- a/WindowsAzureMessaging/WindowsAzureMessaging.xcodeproj/project.pbxproj +++ b/WindowsAzureMessaging/WindowsAzureMessaging.xcodeproj/project.pbxproj @@ -231,6 +231,12 @@ 4C3EEBA024C8BA5F0096C133 /* HTTPStubsMethodSwizzling.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CA7329324A2D020006AC99D /* HTTPStubsMethodSwizzling.h */; }; 4C3EEBA124C8BA600096C133 /* HTTPStubsMethodSwizzling.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CA7329324A2D020006AC99D /* HTTPStubsMethodSwizzling.h */; }; 4C3EEBA224C8BA600096C133 /* HTTPStubsMethodSwizzling.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CA7329324A2D020006AC99D /* HTTPStubsMethodSwizzling.h */; }; + 4C8C7D4926BC732500A39A9B /* ANHApplicationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C8C7D4826BC732500A39A9B /* ANHApplicationProvider.h */; }; + 4C8C7D4A26BC732500A39A9B /* ANHApplicationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C8C7D4826BC732500A39A9B /* ANHApplicationProvider.h */; }; + 4C8C7D4B26BC732500A39A9B /* ANHApplicationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C8C7D4826BC732500A39A9B /* ANHApplicationProvider.h */; }; + 4C8C7D4D26BC740C00A39A9B /* ANHApplicationProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8C7D4C26BC740C00A39A9B /* ANHApplicationProvider.m */; }; + 4C8C7D4E26BC740C00A39A9B /* ANHApplicationProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8C7D4C26BC740C00A39A9B /* ANHApplicationProvider.m */; }; + 4C8C7D4F26BC740C00A39A9B /* ANHApplicationProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8C7D4C26BC740C00A39A9B /* ANHApplicationProvider.m */; }; 4CA730EE24A14FF2006AC99D /* WindowsAzureMessagingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA730ED24A14FF2006AC99D /* WindowsAzureMessagingTests.m */; }; 4CA730F024A14FF2006AC99D /* WindowsAzureMessaging.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CA730E224A14FF2006AC99D /* WindowsAzureMessaging.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4CA7312324A15A25006AC99D /* WindowsAzureMessaging.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CA730E224A14FF2006AC99D /* WindowsAzureMessaging.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -627,6 +633,8 @@ 4C67369325A51EB70041F83D /* XCFramework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = XCFramework.xcconfig; path = ../../../Config/XCFramework.xcconfig; sourceTree = ""; }; 4C67369625A5211A0041F83D /* tvOS Universal.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "tvOS Universal.xcconfig"; path = "../../../Config/tvOS Universal.xcconfig"; sourceTree = ""; }; 4C67369725A5211A0041F83D /* iOS Universal.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "iOS Universal.xcconfig"; path = "../../../Config/iOS Universal.xcconfig"; sourceTree = ""; }; + 4C8C7D4826BC732500A39A9B /* ANHApplicationProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ANHApplicationProvider.h; sourceTree = ""; }; + 4C8C7D4C26BC740C00A39A9B /* ANHApplicationProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ANHApplicationProvider.m; sourceTree = ""; }; 4CA730DF24A14FF2006AC99D /* WindowsAzureMessaging.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WindowsAzureMessaging.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4CA730E224A14FF2006AC99D /* WindowsAzureMessaging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WindowsAzureMessaging.h; sourceTree = ""; }; 4CA730E324A14FF2006AC99D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -997,6 +1005,8 @@ children = ( 4C10498F24ABD6B600FA339E /* DelegateForwarder */, 4CA732F224A3DAC2006AC99D /* ANHApplication.h */, + 4C8C7D4826BC732500A39A9B /* ANHApplicationProvider.h */, + 4C8C7D4C26BC740C00A39A9B /* ANHApplicationProvider.m */, 4CF272FF26BB50FD0018E048 /* ANHAsync.h */, 4CA731F324A1C2A2006AC99D /* MSDebounceInstallationManager.h */, 4CA731F624A1C2CF006AC99D /* MSDebounceInstallationManager.m */, @@ -1138,6 +1148,7 @@ 4C3EEB0D24C8AD2E0096C133 /* ANHHttpUtil.h in Headers */, 4C3EEB9C24C8BA130096C133 /* HTTPStubsPathHelpers.h in Headers */, 4C3EEBA224C8BA600096C133 /* HTTPStubsMethodSwizzling.h in Headers */, + 4C8C7D4B26BC732500A39A9B /* ANHApplicationProvider.h in Headers */, 4C3EEB9B24C8BA100096C133 /* HTTPStubs.h in Headers */, 4C3EEB1724C8AD530096C133 /* ANHDelegateForwarder.h in Headers */, 4C3EEB4024C8AE610096C133 /* MSInstallationManagementDelegate.h in Headers */, @@ -1200,6 +1211,7 @@ 4C1049AF24ABE92100FA339E /* ANHUserNotificationCenterDelegateForwarder.h in Headers */, 4CA7335024A42C64006AC99D /* MSInstallation+Private.h in Headers */, 4C3EEBA024C8BA5F0096C133 /* HTTPStubsMethodSwizzling.h in Headers */, + 4C8C7D4926BC732500A39A9B /* ANHApplicationProvider.h in Headers */, 4CA731BE24A1893C006AC99D /* SBConnectionString.h in Headers */, 4CA732B924A2D04E006AC99D /* Compatibility.h in Headers */, 4CA7317824A18082006AC99D /* ANHHttpClientDelegate.h in Headers */, @@ -1285,6 +1297,7 @@ 4C1049B924ABF83500FA339E /* ANHNotificationHubAppDelegateForwarder.h in Headers */, 4C13E51D253E4B9A0068A1B7 /* MSNotificationHubOptions.h in Headers */, 4C3EEB2424C8ADDC0096C133 /* MSInstallationManager+Private.h in Headers */, + 4C8C7D4A26BC732500A39A9B /* ANHApplicationProvider.h in Headers */, 4CA731F524A1C2A2006AC99D /* MSDebounceInstallationManager.h in Headers */, 4CA7318C24A18613006AC99D /* MSInstallationEnrichmentDelegate.h in Headers */, 4CA7318F24A18662006AC99D /* MSInstallationLifecycleDelegate.h in Headers */, @@ -1972,6 +1985,7 @@ 4C3EEB4224C8AFE00096C133 /* SBRegistration.m in Sources */, 4C3EEB0024C8ABB40096C133 /* SBLocalStorage.m in Sources */, 4C3EEB1924C8AD5A0096C133 /* ANHDelegateForwarder.m in Sources */, + 4C8C7D4F26BC740C00A39A9B /* ANHApplicationProvider.m in Sources */, 4C3EEB2224C8ADD30096C133 /* MSInstallationManager.m in Sources */, 4C3EEB1B24C8AD610096C133 /* ANHNotificationHubAppDelegateForwarder.m in Sources */, 4C3EEB0224C8ABBD0096C133 /* SBNotificationHubHelper.m in Sources */, @@ -2032,6 +2046,7 @@ 4CA731B024A187A6006AC99D /* SBTokenProvider.m in Sources */, 4CA731D524A1B971006AC99D /* MSInstallation.m in Sources */, 4CA731CA24A1902F006AC99D /* MSLocalStorage.m in Sources */, + 4C8C7D4D26BC740C00A39A9B /* ANHApplicationProvider.m in Sources */, 4CA731A824A187A6006AC99D /* SBURLConnection.m in Sources */, 4CA731AE24A187A6006AC99D /* SBStoredRegistrationEntry.m in Sources */, 4C1049A024ABE45A00FA339E /* ANHDelegateForwarder.m in Sources */, @@ -2121,6 +2136,7 @@ 4C1049BC24ABF85800FA339E /* ANHNotificationHubAppDelegateForwarder.m in Sources */, 4CA7317624A18041006AC99D /* ANHHttpClient.m in Sources */, 4CA7316024A17B4C006AC99D /* ANHDispatcherUtil.m in Sources */, + 4C8C7D4E26BC740C00A39A9B /* ANHApplicationProvider.m in Sources */, 4CA7318024A180E5006AC99D /* ANHHttpUtil.m in Sources */, 4C1049A124ABE45A00FA339E /* ANHDelegateForwarder.m in Sources */, 4CA731C524A18B41006AC99D /* MSTokenProvider.m in Sources */, diff --git a/WindowsAzureMessaging/WindowsAzureMessaging/Internal/ANHApplicationProvider.h b/WindowsAzureMessaging/WindowsAzureMessaging/Internal/ANHApplicationProvider.h new file mode 100644 index 0000000..015a262 --- /dev/null +++ b/WindowsAzureMessaging/WindowsAzureMessaging/Internal/ANHApplicationProvider.h @@ -0,0 +1,37 @@ +//---------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +//---------------------------------------------------------------- + +#import + +#if TARGET_OS_OSX +#import +#else +#import +#endif + +@interface ANHApplicationProvider : NSObject + +/** + * Get the Shared Application from either NSApplication (MacOS) or UIApplication. + * + * @return The shared application. + */ +#if TARGET_OS_OSX ++ (NSApplication *)sharedApplication; +#else ++ (UIApplication *)sharedApplication; +#endif + +/** + * Get the App Delegate. + * + * @return The delegate of the app object or nil if not accessible. + */ +#if TARGET_OS_OSX ++ (id)sharedAppDelegate; +#else ++ (id)sharedAppDelegate; +#endif + +@end diff --git a/WindowsAzureMessaging/WindowsAzureMessaging/Internal/ANHApplicationProvider.m b/WindowsAzureMessaging/WindowsAzureMessaging/Internal/ANHApplicationProvider.m new file mode 100644 index 0000000..c9e11ef --- /dev/null +++ b/WindowsAzureMessaging/WindowsAzureMessaging/Internal/ANHApplicationProvider.m @@ -0,0 +1,35 @@ +//---------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +//---------------------------------------------------------------- + +#import "ANHApplicationProvider.h" + +@implementation ANHApplicationProvider + +#if TARGET_OS_OSX ++ (NSApplication *)sharedApplication { + + // Compute selector at runtime for more discretion. + SEL sharedAppSel = NSSelectorFromString(@"sharedApplication"); + return ((NSApplication * (*)(id, SEL))[[NSApplication class] methodForSelector:sharedAppSel])([NSApplication class], sharedAppSel); +} +#else ++ (UIApplication *)sharedApplication { + + // Compute selector at runtime for more discretion. + SEL sharedAppSel = NSSelectorFromString(@"sharedApplication"); + return ((UIApplication * (*)(id, SEL))[[UIApplication class] methodForSelector:sharedAppSel])([UIApplication class], sharedAppSel); +} +#endif + +#if TARGET_OS_OSX ++ (id)sharedAppDelegate { + return [self sharedApplication].delegate; +} +#else ++ (id)sharedAppDelegate { + return [self sharedApplication].delegate; +} +#endif + +@end diff --git a/WindowsAzureMessaging/WindowsAzureMessaging/MSNotificationHub.m b/WindowsAzureMessaging/WindowsAzureMessaging/MSNotificationHub.m index a1d3955..28c8493 100644 --- a/WindowsAzureMessaging/WindowsAzureMessaging/MSNotificationHub.m +++ b/WindowsAzureMessaging/WindowsAzureMessaging/MSNotificationHub.m @@ -12,6 +12,7 @@ #import #endif +#import "ANHApplicationProvider.h" #import "ANHNotificationHubAppDelegateForwarder.h" #import "ANHUserNotificationCenterDelegateForwarder.h" #import "MSDebounceInstallationManager.h" @@ -177,10 +178,11 @@ static void *UserNotificationCenterDelegateContext = &UserNotificationCenterDele UIUserNotificationType allNotificationTypes = (UIUserNotificationType)(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; - [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; - } - [[UIApplication sharedApplication] registerForRemoteNotifications]; + [[ANHApplicationProvider sharedApplication] registerUserNotificationSettings:settings]; #pragma GCC diagnostic pop + } + + [[ANHApplicationProvider sharedApplication] registerForRemoteNotifications]; #endif }