From 24eb5fb98dfb2c100da360652eef4f3970975ff0 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 27 Mar 2022 21:03:04 +0200 Subject: [PATCH 01/18] Added files for basic APNS example --- .../project.pbxproj | 387 ++++++++++++++++++ .../AblyCocoaAPNSExample.entitlements | 8 + .../AblyCocoaAPNSExample/AblyHelper.swift | 77 ++++ .../AblyCocoaAPNSExample/App.swift | 25 ++ .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 98 +++++ .../Assets.xcassets/Contents.json | 6 + .../AblyCocoaAPNSExample/ContentView.swift | 55 +++ .../AblyCocoaAPNSExample/Info.plist | 5 + .../Preview Assets.xcassets/Contents.json | 6 + 10 files changed, 678 insertions(+) create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/App.swift create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/Contents.json create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Info.plist create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Preview Content/Preview Assets.xcassets/Contents.json diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj new file mode 100644 index 000000000..638a10a9d --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj @@ -0,0 +1,387 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 8405EE8427F0B06800C9E461 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8405EE8327F0B06800C9E461 /* App.swift */; }; + 8405EE8627F0B06800C9E461 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8405EE8527F0B06800C9E461 /* ContentView.swift */; }; + 8405EE8827F0B06C00C9E461 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8405EE8727F0B06C00C9E461 /* Assets.xcassets */; }; + 8405EE8B27F0B06C00C9E461 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8405EE8A27F0B06C00C9E461 /* Preview Assets.xcassets */; }; + 842F124A27F0B29D0029692E /* AblyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842F124927F0B29D0029692E /* AblyHelper.swift */; }; + 842F124F27F0ECC50029692E /* Ably in Frameworks */ = {isa = PBXBuildFile; productRef = 842F124E27F0ECC50029692E /* Ably */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 8405EE8027F0B06800C9E461 /* Push Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Push Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 8405EE8327F0B06800C9E461 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = ""; }; + 8405EE8527F0B06800C9E461 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 8405EE8727F0B06C00C9E461 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 8405EE8A27F0B06C00C9E461 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 842F124927F0B29D0029692E /* AblyHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AblyHelper.swift; sourceTree = ""; }; + 842F124B27F0BFC10029692E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 842F124C27F0BFD40029692E /* AblyCocoaAPNSExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AblyCocoaAPNSExample.entitlements; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8405EE7D27F0B06800C9E461 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 842F124F27F0ECC50029692E /* Ably in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 8405EE7727F0B06800C9E461 = { + isa = PBXGroup; + children = ( + 8405EE8227F0B06800C9E461 /* AblyCocoaAPNSExample */, + 8405EE8127F0B06800C9E461 /* Products */, + ); + sourceTree = ""; + }; + 8405EE8127F0B06800C9E461 /* Products */ = { + isa = PBXGroup; + children = ( + 8405EE8027F0B06800C9E461 /* Push Example.app */, + ); + name = Products; + sourceTree = ""; + }; + 8405EE8227F0B06800C9E461 /* AblyCocoaAPNSExample */ = { + isa = PBXGroup; + children = ( + 8405EE8327F0B06800C9E461 /* App.swift */, + 842F124927F0B29D0029692E /* AblyHelper.swift */, + 8405EE8527F0B06800C9E461 /* ContentView.swift */, + 842F124B27F0BFC10029692E /* Info.plist */, + 8405EE8727F0B06C00C9E461 /* Assets.xcassets */, + 842F124C27F0BFD40029692E /* AblyCocoaAPNSExample.entitlements */, + 8405EE8927F0B06C00C9E461 /* Preview Content */, + ); + path = AblyCocoaAPNSExample; + sourceTree = ""; + }; + 8405EE8927F0B06C00C9E461 /* Preview Content */ = { + isa = PBXGroup; + children = ( + 8405EE8A27F0B06C00C9E461 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 8405EE7F27F0B06800C9E461 /* AblyCocoaAPNSExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 8405EE8E27F0B06C00C9E461 /* Build configuration list for PBXNativeTarget "AblyCocoaAPNSExample" */; + buildPhases = ( + 8405EE7C27F0B06800C9E461 /* Sources */, + 8405EE7D27F0B06800C9E461 /* Frameworks */, + 8405EE7E27F0B06800C9E461 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = AblyCocoaAPNSExample; + packageProductDependencies = ( + 842F124E27F0ECC50029692E /* Ably */, + ); + productName = AblyCocoaAPNSExample; + productReference = 8405EE8027F0B06800C9E461 /* Push Example.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 8405EE7827F0B06800C9E461 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1300; + LastUpgradeCheck = 1300; + TargetAttributes = { + 8405EE7F27F0B06800C9E461 = { + CreatedOnToolsVersion = 13.0; + }; + }; + }; + buildConfigurationList = 8405EE7B27F0B06800C9E461 /* Build configuration list for PBXProject "AblyCocoaAPNSExample" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 8405EE7727F0B06800C9E461; + packageReferences = ( + 842F124D27F0ECC50029692E /* XCRemoteSwiftPackageReference "ably-cocoa" */, + ); + productRefGroup = 8405EE8127F0B06800C9E461 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 8405EE7F27F0B06800C9E461 /* AblyCocoaAPNSExample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 8405EE7E27F0B06800C9E461 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8405EE8B27F0B06C00C9E461 /* Preview Assets.xcassets in Resources */, + 8405EE8827F0B06C00C9E461 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8405EE7C27F0B06800C9E461 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8405EE8627F0B06800C9E461 /* ContentView.swift in Sources */, + 842F124A27F0B29D0029692E /* AblyHelper.swift in Sources */, + 8405EE8427F0B06800C9E461 /* App.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 8405EE8C27F0B06C00C9E461 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 8405EE8D27F0B06C00C9E461 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 8405EE8F27F0B06C00C9E461 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"AblyCocoaAPNSExample/Preview Content\""; + DEVELOPMENT_TEAM = ""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = AblyCocoaAPNSExample/Info.plist; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "io.ably.basic-apns-example"; + PRODUCT_NAME = "Push Example"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 8405EE9027F0B06C00C9E461 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"AblyCocoaAPNSExample/Preview Content\""; + DEVELOPMENT_TEAM = ""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = AblyCocoaAPNSExample/Info.plist; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "io.ably.basic-apns-example"; + PRODUCT_NAME = "Push Example"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 8405EE7B27F0B06800C9E461 /* Build configuration list for PBXProject "AblyCocoaAPNSExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8405EE8C27F0B06C00C9E461 /* Debug */, + 8405EE8D27F0B06C00C9E461 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 8405EE8E27F0B06C00C9E461 /* Build configuration list for PBXNativeTarget "AblyCocoaAPNSExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8405EE8F27F0B06C00C9E461 /* Debug */, + 8405EE9027F0B06C00C9E461 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 842F124D27F0ECC50029692E /* XCRemoteSwiftPackageReference "ably-cocoa" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/ably/ably-cocoa"; + requirement = { + branch = main; + kind = branch; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 842F124E27F0ECC50029692E /* Ably */ = { + isa = XCSwiftPackageProductDependency; + package = 842F124D27F0ECC50029692E /* XCRemoteSwiftPackageReference "ably-cocoa" */; + productName = Ably; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 8405EE7827F0B06800C9E461 /* Project object */; +} diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements new file mode 100644 index 000000000..903def2af --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift new file mode 100644 index 000000000..6214315fc --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -0,0 +1,77 @@ +import Ably +import UIKit + +class AblyHelper: NSObject { + + static let shared = AblyHelper() + + private(set) var realtime: ARTRealtime! + + private let key = "" + + private override init() { + super.init() + let options = ARTClientOptions(key: key) + options.clientId = "basic-apns-example" + self.realtime = ARTRealtime(options: options) + UNUserNotificationCenter.current().delegate = self + } +} + +extension AblyHelper: UNUserNotificationCenterDelegate { + + static func requestAPNSAuthorization() { + UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { granted, error in + DispatchQueue.main.async() { + UIApplication.shared.registerForRemoteNotifications() + print("Push auth: \(error?.localizedDescription ?? (granted ? "Granted" : "Not Granted"))") + } + } + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + completionHandler() + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + print("Got push notification!") + completionHandler([.banner, .sound]) + } +} + +extension AblyHelper { + + func printIdentityToken() { + guard + let tokenData = UserDefaults.standard.value(forKey: "ARTDeviceIdentityToken") as? Data, + let tokenInfo = ARTDeviceIdentityTokenDetails.unarchive(tokenData) + else { + print("INDENTITY TOKEN: doesn't exist") + return + } + print("INDENTITY TOKEN:\n\(tokenInfo.token)") + } + + func getDeviceDetails(_ callback: @escaping (ARTDeviceDetails?, ARTErrorInfo?) -> ()) { + realtime.push.admin.deviceRegistrations.get(realtime.device.id, callback: callback) + } + + func sendAdminPush() { + let recipient = [ + "deviceId": realtime.device.id + ] + let data = [ + "notification": [ + "title": "Hello", + "body": "This push was sent with deviceId" + ], + "data": [ + "foo": "bar", + "baz": "qux" + ] + ] + realtime.push.admin.publish(recipient, data: data) { error in + print("Result: \(error?.localizedDescription ?? "Success")") + } + } +} diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/App.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/App.swift new file mode 100644 index 000000000..4fdfbf67e --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/App.swift @@ -0,0 +1,25 @@ +import Ably +import SwiftUI + +@main +struct AblyCocoaAPNSExampleApp: App { + + @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate + + var body: some Scene { + WindowGroup { + ContentView() + } + } +} + +class AppDelegate: NSObject, UIApplicationDelegate { + + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + ARTPush.didRegisterForRemoteNotifications(withDeviceToken: deviceToken, realtime: AblyHelper.shared.realtime) + } + + func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { + ARTPush.didFailToRegisterForRemoteNotificationsWithError(error, realtime: AblyHelper.shared.realtime) + } +} diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AccentColor.colorset/Contents.json b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 000000000..eb8789700 --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AppIcon.appiconset/Contents.json b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..9221b9bb1 --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/Contents.json b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift new file mode 100644 index 000000000..0c75acc15 --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift @@ -0,0 +1,55 @@ +import Ably +import SwiftUI + +struct ContentView: View { + + @State var showDeviceDetailsAlert = false + @State var deviceDetails: ARTDeviceDetails? + @State var deviceDetailsError: ARTErrorInfo? + + var body: some View { + VStack { + Spacer() + Button("Activate") { + AblyHelper.requestAPNSAuthorization() + AblyHelper.shared.realtime.push.activate() + } + .padding() + Button("Dectivate") { + AblyHelper.shared.realtime.push.deactivate() + } + .padding() + Button("Print Token") { + AblyHelper.shared.printIdentityToken() + } + .padding() + Button("Device Details") { + AblyHelper.shared.getDeviceDetails { details, error in + deviceDetails = details + deviceDetailsError = error + showDeviceDetailsAlert = true + } + } + .alert(isPresented: $showDeviceDetailsAlert) { + if deviceDetails != nil { + return Alert(title: Text("Device Details"), message: Text("\(deviceDetails!)")) + } else if deviceDetailsError != nil { + return Alert(title: Text("Device Details Error"), message: Text("\(deviceDetailsError!)")) + } + return Alert(title: Text("Device Details Error"), message: Text("Unknown result.")) + } + .padding() + Button("Send Push") { + AblyHelper.shared.sendAdminPush() + } + .padding() + Spacer() + } + } +} + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + ContentView() + } +} diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Info.plist b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Info.plist new file mode 100644 index 000000000..0c67376eb --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Info.plist @@ -0,0 +1,5 @@ + + + + + diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Preview Content/Preview Assets.xcassets/Contents.json b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} From 1b2902e68d00eacf00bcb375ac7bb88aae81bbe2 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Tue, 29 Mar 2022 17:27:50 +0200 Subject: [PATCH 02/18] Update Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift Typo fix Co-authored-by: Lawrence Forooghian <53756884+lawrence-forooghian@users.noreply.github.com> --- .../AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift index 6214315fc..cfdee8cc3 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -46,7 +46,7 @@ extension AblyHelper { let tokenData = UserDefaults.standard.value(forKey: "ARTDeviceIdentityToken") as? Data, let tokenInfo = ARTDeviceIdentityTokenDetails.unarchive(tokenData) else { - print("INDENTITY TOKEN: doesn't exist") + print("IDENTITY TOKEN: doesn't exist") return } print("INDENTITY TOKEN:\n\(tokenInfo.token)") From c2f51e8b49b2fc42736822f91b4c92ea8c7931a9 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Tue, 29 Mar 2022 17:27:56 +0200 Subject: [PATCH 03/18] Update Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift typo fix Co-authored-by: Lawrence Forooghian <53756884+lawrence-forooghian@users.noreply.github.com> --- .../AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift index cfdee8cc3..9be2990bb 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -49,7 +49,7 @@ extension AblyHelper { print("IDENTITY TOKEN: doesn't exist") return } - print("INDENTITY TOKEN:\n\(tokenInfo.token)") + print("IDENTITY TOKEN:\n\(tokenInfo.token)") } func getDeviceDetails(_ callback: @escaping (ARTDeviceDetails?, ARTErrorInfo?) -> ()) { From bba3299ac0337f3901f2a46b1a050f56e3fed64f Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 2 Apr 2022 16:31:56 +0200 Subject: [PATCH 04/18] Local Ably SPM package instead of remote --- .../project.pbxproj | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj index 638a10a9d..0bea85e3d 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj @@ -12,7 +12,7 @@ 8405EE8827F0B06C00C9E461 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8405EE8727F0B06C00C9E461 /* Assets.xcassets */; }; 8405EE8B27F0B06C00C9E461 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8405EE8A27F0B06C00C9E461 /* Preview Assets.xcassets */; }; 842F124A27F0B29D0029692E /* AblyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842F124927F0B29D0029692E /* AblyHelper.swift */; }; - 842F124F27F0ECC50029692E /* Ably in Frameworks */ = {isa = PBXBuildFile; productRef = 842F124E27F0ECC50029692E /* Ably */; }; + 848694D127F8958F00B41A5D /* Ably in Frameworks */ = {isa = PBXBuildFile; productRef = 848694D027F8958F00B41A5D /* Ably */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -24,6 +24,7 @@ 842F124927F0B29D0029692E /* AblyHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AblyHelper.swift; sourceTree = ""; }; 842F124B27F0BFC10029692E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 842F124C27F0BFD40029692E /* AblyCocoaAPNSExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AblyCocoaAPNSExample.entitlements; sourceTree = ""; }; + 848694CE27F8957400B41A5D /* ably-cocoa */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "ably-cocoa"; path = ../..; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -31,7 +32,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 842F124F27F0ECC50029692E /* Ably in Frameworks */, + 848694D127F8958F00B41A5D /* Ably in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -42,7 +43,9 @@ isa = PBXGroup; children = ( 8405EE8227F0B06800C9E461 /* AblyCocoaAPNSExample */, + 848694CD27F8957400B41A5D /* Packages */, 8405EE8127F0B06800C9E461 /* Products */, + 848694CF27F8958F00B41A5D /* Frameworks */, ); sourceTree = ""; }; @@ -76,6 +79,21 @@ path = "Preview Content"; sourceTree = ""; }; + 848694CD27F8957400B41A5D /* Packages */ = { + isa = PBXGroup; + children = ( + 848694CE27F8957400B41A5D /* ably-cocoa */, + ); + name = Packages; + sourceTree = ""; + }; + 848694CF27F8958F00B41A5D /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -93,7 +111,7 @@ ); name = AblyCocoaAPNSExample; packageProductDependencies = ( - 842F124E27F0ECC50029692E /* Ably */, + 848694D027F8958F00B41A5D /* Ably */, ); productName = AblyCocoaAPNSExample; productReference = 8405EE8027F0B06800C9E461 /* Push Example.app */; @@ -124,7 +142,6 @@ ); mainGroup = 8405EE7727F0B06800C9E461; packageReferences = ( - 842F124D27F0ECC50029692E /* XCRemoteSwiftPackageReference "ably-cocoa" */, ); productRefGroup = 8405EE8127F0B06800C9E461 /* Products */; projectDirPath = ""; @@ -364,21 +381,9 @@ }; /* End XCConfigurationList section */ -/* Begin XCRemoteSwiftPackageReference section */ - 842F124D27F0ECC50029692E /* XCRemoteSwiftPackageReference "ably-cocoa" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/ably/ably-cocoa"; - requirement = { - branch = main; - kind = branch; - }; - }; -/* End XCRemoteSwiftPackageReference section */ - /* Begin XCSwiftPackageProductDependency section */ - 842F124E27F0ECC50029692E /* Ably */ = { + 848694D027F8958F00B41A5D /* Ably */ = { isa = XCSwiftPackageProductDependency; - package = 842F124D27F0ECC50029692E /* XCRemoteSwiftPackageReference "ably-cocoa" */; productName = Ably; }; /* End XCSwiftPackageProductDependency section */ From 9b459d40ffd46fb3ee6a22400dc33b5271365d2b Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 2 Apr 2022 16:41:44 +0200 Subject: [PATCH 05/18] Renamed function to requestUserNotificationAuthorization --- .../AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift | 2 +- .../AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift index 9be2990bb..6eb4b73c0 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -20,7 +20,7 @@ class AblyHelper: NSObject { extension AblyHelper: UNUserNotificationCenterDelegate { - static func requestAPNSAuthorization() { + static func requestUserNotificationAuthorization() { UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { granted, error in DispatchQueue.main.async() { UIApplication.shared.registerForRemoteNotifications() diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift index 0c75acc15..f896980e6 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift @@ -11,7 +11,7 @@ struct ContentView: View { VStack { Spacer() Button("Activate") { - AblyHelper.requestAPNSAuthorization() + AblyHelper.requestUserNotificationAuthorization() AblyHelper.shared.realtime.push.activate() } .padding() From bfa071b74ca36bfc4f7b989f183ff68727a3ce85 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 2 Apr 2022 16:47:46 +0200 Subject: [PATCH 06/18] Incapsulated other methods into helper --- .../AblyCocoaAPNSExample/AblyHelper.swift | 9 +++++++++ .../AblyCocoaAPNSExample/ContentView.swift | 5 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift index 6eb4b73c0..a8af8706c 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -41,6 +41,15 @@ extension AblyHelper: UNUserNotificationCenterDelegate { extension AblyHelper { + func activatePush() { + Self.requestUserNotificationAuthorization() + realtime.push.activate() + } + + func deactivatePush() { + realtime.push.deactivate() + } + func printIdentityToken() { guard let tokenData = UserDefaults.standard.value(forKey: "ARTDeviceIdentityToken") as? Data, diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift index f896980e6..1a9dfa983 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift @@ -11,12 +11,11 @@ struct ContentView: View { VStack { Spacer() Button("Activate") { - AblyHelper.requestUserNotificationAuthorization() - AblyHelper.shared.realtime.push.activate() + AblyHelper.shared.activatePush() } .padding() Button("Dectivate") { - AblyHelper.shared.realtime.push.deactivate() + AblyHelper.shared.deactivatePush() } .padding() Button("Print Token") { From c028291b9af87154b21be9beddc36566d5d1e6e9 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 2 Apr 2022 16:48:41 +0200 Subject: [PATCH 07/18] cleanup --- .../AblyCocoaAPNSExample/AblyHelper.swift | 42 +++++++++---------- .../AblyCocoaAPNSExample/ContentView.swift | 3 +- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift index a8af8706c..fd086f994 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -18,27 +18,6 @@ class AblyHelper: NSObject { } } -extension AblyHelper: UNUserNotificationCenterDelegate { - - static func requestUserNotificationAuthorization() { - UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { granted, error in - DispatchQueue.main.async() { - UIApplication.shared.registerForRemoteNotifications() - print("Push auth: \(error?.localizedDescription ?? (granted ? "Granted" : "Not Granted"))") - } - } - } - - func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { - completionHandler() - } - - func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { - print("Got push notification!") - completionHandler([.banner, .sound]) - } -} - extension AblyHelper { func activatePush() { @@ -84,3 +63,24 @@ extension AblyHelper { } } } + +extension AblyHelper: UNUserNotificationCenterDelegate { + + static func requestUserNotificationAuthorization() { + UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { granted, error in + DispatchQueue.main.async() { + UIApplication.shared.registerForRemoteNotifications() + print("Push auth: \(error?.localizedDescription ?? (granted ? "Granted" : "Not Granted"))") + } + } + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + completionHandler() + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + print("Got push notification!") + completionHandler([.banner, .sound]) + } +} diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift index 1a9dfa983..b2768a91f 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift @@ -32,7 +32,8 @@ struct ContentView: View { .alert(isPresented: $showDeviceDetailsAlert) { if deviceDetails != nil { return Alert(title: Text("Device Details"), message: Text("\(deviceDetails!)")) - } else if deviceDetailsError != nil { + } + else if deviceDetailsError != nil { return Alert(title: Text("Device Details Error"), message: Text("\(deviceDetailsError!)")) } return Alert(title: Text("Device Details Error"), message: Text("Unknown result.")) From 30018ad0497d860f27a0fabd9988a8fb44a44ff4 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 2 Apr 2022 19:26:51 +0200 Subject: [PATCH 08/18] Added ARTPushRegistererDelegate --- .../AblyCocoaAPNSExample/AblyHelper.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift index fd086f994..71de23bbf 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -13,6 +13,7 @@ class AblyHelper: NSObject { super.init() let options = ARTClientOptions(key: key) options.clientId = "basic-apns-example" + options.pushRegistererDelegate = self self.realtime = ARTRealtime(options: options) UNUserNotificationCenter.current().delegate = self } @@ -64,6 +65,17 @@ extension AblyHelper { } } +extension AblyHelper: ARTPushRegistererDelegate { + + func didActivateAblyPush(_ error: ARTErrorInfo?) { + print("Push activation: \(error?.localizedDescription ?? "Success")") + } + + func didDeactivateAblyPush(_ error: ARTErrorInfo?) { + print("Push deactivation: \(error?.localizedDescription ?? "Success")") + } +} + extension AblyHelper: UNUserNotificationCenterDelegate { static func requestUserNotificationAuthorization() { From e89c99d5cff73da45863583eb82ebd982f242edc Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 2 Apr 2022 19:34:14 +0200 Subject: [PATCH 09/18] Improved admin push method --- .../AblyCocoaAPNSExample/AblyHelper.swift | 9 +++++---- .../AblyCocoaAPNSExample/ContentView.swift | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift index 71de23bbf..900d159a6 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -45,14 +45,15 @@ extension AblyHelper { realtime.push.admin.deviceRegistrations.get(realtime.device.id, callback: callback) } - func sendAdminPush() { + // For this to work you must turn on 'Push Admin' capability in your API key settings + func sendAdminPush(title: String, body: String) { let recipient = [ "deviceId": realtime.device.id ] let data = [ "notification": [ - "title": "Hello", - "body": "This push was sent with deviceId" + "title": title, + "body": body ], "data": [ "foo": "bar", @@ -60,7 +61,7 @@ extension AblyHelper { ] ] realtime.push.admin.publish(recipient, data: data) { error in - print("Result: \(error?.localizedDescription ?? "Success")") + print("Publish result: \(error?.localizedDescription ?? "Success")") } } } diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift index b2768a91f..0172f4bff 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift @@ -40,7 +40,7 @@ struct ContentView: View { } .padding() Button("Send Push") { - AblyHelper.shared.sendAdminPush() + AblyHelper.shared.sendAdminPush(title: "Hello", body: "This push was sent with deviceId") } .padding() Spacer() From 555ba41a9c376f906b2e3795e35b2ada2f1186ce Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 2 Apr 2022 22:07:57 +0200 Subject: [PATCH 10/18] Explicit failure and instructions in case of missing API key --- .../AblyCocoaAPNSExample/AblyHelper.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift index 900d159a6..75ee0bfd0 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift @@ -7,10 +7,13 @@ class AblyHelper: NSObject { private(set) var realtime: ARTRealtime! - private let key = "" + private let key = "" // Your API Key from your app's dashboard private override init() { super.init() + guard key != "" else { + preconditionFailure("Obtain your API key at https://ably.com/accounts/") + } let options = ARTClientOptions(key: key) options.clientId = "basic-apns-example" options.pushRegistererDelegate = self From db8de23617e4c1252588a7d7d37b5403831f9fad Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 2 Apr 2022 22:43:07 +0200 Subject: [PATCH 11/18] README.md added --- Examples/AblyCocoaAPNSExample/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Examples/AblyCocoaAPNSExample/README.md diff --git a/Examples/AblyCocoaAPNSExample/README.md b/Examples/AblyCocoaAPNSExample/README.md new file mode 100644 index 000000000..65587ec60 --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/README.md @@ -0,0 +1,10 @@ +This app gives you a brief understanding of how Ably's Push Notifications work. +You will need a real iOS device to test this functionality. + +- First, go to https://ably.com/accounts/, create an app and copy API key from API Keys tab of the app's dashboard. +- Insert it instead of an empty string in the `key` property's value inside the `AblyHelper` class. +- Make sure you've selected your development team in the `Signing & Capabilities` tab of the Xcode project target settings and all the provisioning profiles created without errors. +- Build and Run the app on your device. +- Hit "Activate" button, then hit "Print Token". You should see the printed value in the debug output window. You can also hit "Device Details" for additional check. +- Go to the `Notifications` tab of the Ably's app dashboard and scroll to the `Push Inspector` section. Fill in `Title` and `Body` fields of the push notification. Then insert "basic-apns-example" in the `Client ID` field and press enter. Then hit "Push to client" button. You should now see the notification on the screen of your device. +- Also you can send notifications from the app itself if you tick `Push Admin` capability in your API key settings in the app's dashboard. Just hit "Send Push" button to send a predefined push notification which is also will be displayed on your device's screen right away. You can change this behavior in the `UNUserNotificationCenterDelegate` extension for the `AblyHelper` by editing `completionHandler([.banner, .sound])` line of code. \ No newline at end of file From a4cd127d03a72ff36b211f41987e40998da8e5f7 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 3 Apr 2022 17:00:05 +0200 Subject: [PATCH 12/18] Build scheme added --- .../xcschemes/AblyCocoaAPNSExample.xcscheme | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/xcshareddata/xcschemes/AblyCocoaAPNSExample.xcscheme diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/xcshareddata/xcschemes/AblyCocoaAPNSExample.xcscheme b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/xcshareddata/xcschemes/AblyCocoaAPNSExample.xcscheme new file mode 100644 index 000000000..2f53a2d30 --- /dev/null +++ b/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/xcshareddata/xcschemes/AblyCocoaAPNSExample.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ba5c780ab92947aee470b67fea260f093036d9b1 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 3 Apr 2022 17:11:08 +0200 Subject: [PATCH 13/18] Added workflow step to build APNS Example project --- .github/workflows/integration-test-iOS14_4.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/integration-test-iOS14_4.yaml b/.github/workflows/integration-test-iOS14_4.yaml index 0b45b8e61..f4e0fd182 100644 --- a/.github/workflows/integration-test-iOS14_4.yaml +++ b/.github/workflows/integration-test-iOS14_4.yaml @@ -63,6 +63,11 @@ jobs: pod repo update pod install bundle exec fastlane scan -s Tests --output-directory "fastlane/test_output/examples/test_iOS14_4" + + - name: Build APNS Example Project + working-directory: ./Examples/AblyCocoaAPNSExample + run: | + xcodebuild build -scheme "AblyCocoaAPNSExample" -destination "platform=iOS Simulator,name=iPhone 13" -configuration "Debug" - name: Xcodebuild Logs Artifact if: always() From 99b3f16c9c2f7ec8aa29509eb5f624c56bfd8f61 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 3 Apr 2022 17:43:23 +0200 Subject: [PATCH 14/18] xcodebuild destination iPhone 12 --- .github/workflows/integration-test-iOS14_4.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-test-iOS14_4.yaml b/.github/workflows/integration-test-iOS14_4.yaml index f4e0fd182..5835449bc 100644 --- a/.github/workflows/integration-test-iOS14_4.yaml +++ b/.github/workflows/integration-test-iOS14_4.yaml @@ -67,7 +67,7 @@ jobs: - name: Build APNS Example Project working-directory: ./Examples/AblyCocoaAPNSExample run: | - xcodebuild build -scheme "AblyCocoaAPNSExample" -destination "platform=iOS Simulator,name=iPhone 13" -configuration "Debug" + xcodebuild build -scheme "AblyCocoaAPNSExample" -destination "platform=iOS Simulator,name=iPhone 12" -configuration "Debug" - name: Xcodebuild Logs Artifact if: always() From f310e5cfde939cf37df42b29d4753a52fd8b83d6 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 10 Apr 2022 14:25:44 +0200 Subject: [PATCH 15/18] Renamed to AblyPushExample --- .../project.pbxproj | 52 +++++++++---------- .../xcschemes/AblyPushExample.xcscheme} | 18 +++---- .../AblyPushExample}/AblyHelper.swift | 0 .../AblyPushExample.entitlements} | 0 .../AblyPushExample}/App.swift | 0 .../AccentColor.colorset/Contents.json | 0 .../AppIcon.appiconset/Contents.json | 0 .../Assets.xcassets/Contents.json | 0 .../AblyPushExample}/ContentView.swift | 0 .../AblyPushExample}/Info.plist | 0 .../Preview Assets.xcassets/Contents.json | 0 .../README.md | 0 12 files changed, 35 insertions(+), 35 deletions(-) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj => AblyPush/AblyPushExample.xcodeproj}/project.pbxproj (88%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/xcshareddata/xcschemes/AblyCocoaAPNSExample.xcscheme => AblyPush/AblyPushExample.xcodeproj/xcshareddata/xcschemes/AblyPushExample.xcscheme} (81%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample => AblyPush/AblyPushExample}/AblyHelper.swift (100%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements => AblyPush/AblyPushExample/AblyPushExample.entitlements} (100%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample => AblyPush/AblyPushExample}/App.swift (100%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample => AblyPush/AblyPushExample}/Assets.xcassets/AccentColor.colorset/Contents.json (100%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample => AblyPush/AblyPushExample}/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample => AblyPush/AblyPushExample}/Assets.xcassets/Contents.json (100%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample => AblyPush/AblyPushExample}/ContentView.swift (100%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample => AblyPush/AblyPushExample}/Info.plist (100%) rename Examples/{AblyCocoaAPNSExample/AblyCocoaAPNSExample => AblyPush/AblyPushExample}/Preview Content/Preview Assets.xcassets/Contents.json (100%) rename Examples/{AblyCocoaAPNSExample => AblyPush}/README.md (100%) diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj b/Examples/AblyPush/AblyPushExample.xcodeproj/project.pbxproj similarity index 88% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj rename to Examples/AblyPush/AblyPushExample.xcodeproj/project.pbxproj index 0bea85e3d..bc6d3de8d 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/project.pbxproj +++ b/Examples/AblyPush/AblyPushExample.xcodeproj/project.pbxproj @@ -16,14 +16,14 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 8405EE8027F0B06800C9E461 /* Push Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Push Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 8405EE8027F0B06800C9E461 /* Ably Push.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Ably Push.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 8405EE8327F0B06800C9E461 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = ""; }; 8405EE8527F0B06800C9E461 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 8405EE8727F0B06C00C9E461 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 8405EE8A27F0B06C00C9E461 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 842F124927F0B29D0029692E /* AblyHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AblyHelper.swift; sourceTree = ""; }; 842F124B27F0BFC10029692E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; - 842F124C27F0BFD40029692E /* AblyCocoaAPNSExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AblyCocoaAPNSExample.entitlements; sourceTree = ""; }; + 842F124C27F0BFD40029692E /* AblyPushExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AblyPushExample.entitlements; sourceTree = ""; }; 848694CE27F8957400B41A5D /* ably-cocoa */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "ably-cocoa"; path = ../..; sourceTree = ""; }; /* End PBXFileReference section */ @@ -42,7 +42,7 @@ 8405EE7727F0B06800C9E461 = { isa = PBXGroup; children = ( - 8405EE8227F0B06800C9E461 /* AblyCocoaAPNSExample */, + 8405EE8227F0B06800C9E461 /* AblyPushExample */, 848694CD27F8957400B41A5D /* Packages */, 8405EE8127F0B06800C9E461 /* Products */, 848694CF27F8958F00B41A5D /* Frameworks */, @@ -52,12 +52,12 @@ 8405EE8127F0B06800C9E461 /* Products */ = { isa = PBXGroup; children = ( - 8405EE8027F0B06800C9E461 /* Push Example.app */, + 8405EE8027F0B06800C9E461 /* Ably Push.app */, ); name = Products; sourceTree = ""; }; - 8405EE8227F0B06800C9E461 /* AblyCocoaAPNSExample */ = { + 8405EE8227F0B06800C9E461 /* AblyPushExample */ = { isa = PBXGroup; children = ( 8405EE8327F0B06800C9E461 /* App.swift */, @@ -65,10 +65,10 @@ 8405EE8527F0B06800C9E461 /* ContentView.swift */, 842F124B27F0BFC10029692E /* Info.plist */, 8405EE8727F0B06C00C9E461 /* Assets.xcassets */, - 842F124C27F0BFD40029692E /* AblyCocoaAPNSExample.entitlements */, + 842F124C27F0BFD40029692E /* AblyPushExample.entitlements */, 8405EE8927F0B06C00C9E461 /* Preview Content */, ); - path = AblyCocoaAPNSExample; + path = AblyPushExample; sourceTree = ""; }; 8405EE8927F0B06C00C9E461 /* Preview Content */ = { @@ -97,9 +97,9 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 8405EE7F27F0B06800C9E461 /* AblyCocoaAPNSExample */ = { + 8405EE7F27F0B06800C9E461 /* AblyPushExample */ = { isa = PBXNativeTarget; - buildConfigurationList = 8405EE8E27F0B06C00C9E461 /* Build configuration list for PBXNativeTarget "AblyCocoaAPNSExample" */; + buildConfigurationList = 8405EE8E27F0B06C00C9E461 /* Build configuration list for PBXNativeTarget "AblyPushExample" */; buildPhases = ( 8405EE7C27F0B06800C9E461 /* Sources */, 8405EE7D27F0B06800C9E461 /* Frameworks */, @@ -109,12 +109,12 @@ ); dependencies = ( ); - name = AblyCocoaAPNSExample; + name = AblyPushExample; packageProductDependencies = ( 848694D027F8958F00B41A5D /* Ably */, ); - productName = AblyCocoaAPNSExample; - productReference = 8405EE8027F0B06800C9E461 /* Push Example.app */; + productName = AblyPushExample; + productReference = 8405EE8027F0B06800C9E461 /* Ably Push.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -132,7 +132,7 @@ }; }; }; - buildConfigurationList = 8405EE7B27F0B06800C9E461 /* Build configuration list for PBXProject "AblyCocoaAPNSExample" */; + buildConfigurationList = 8405EE7B27F0B06800C9E461 /* Build configuration list for PBXProject "AblyPushExample" */; compatibilityVersion = "Xcode 13.0"; developmentRegion = en; hasScannedForEncodings = 0; @@ -147,7 +147,7 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 8405EE7F27F0B06800C9E461 /* AblyCocoaAPNSExample */, + 8405EE7F27F0B06800C9E461 /* AblyPushExample */, ); }; /* End PBXProject section */ @@ -299,14 +299,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_ENTITLEMENTS = AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements; + CODE_SIGN_ENTITLEMENTS = AblyPushExample/AblyPushExample.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_ASSET_PATHS = "\"AblyCocoaAPNSExample/Preview Content\""; + DEVELOPMENT_ASSET_PATHS = "\"AblyPushExample/Preview Content\""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_FILE = AblyCocoaAPNSExample/Info.plist; + INFOPLIST_FILE = AblyPushExample/Info.plist; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -318,8 +318,8 @@ "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = "io.ably.basic-apns-example"; - PRODUCT_NAME = "Push Example"; + PRODUCT_BUNDLE_IDENTIFIER = "io.ably.basic-push-example"; + PRODUCT_NAME = "Ably Push"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -331,14 +331,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_ENTITLEMENTS = AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements; + CODE_SIGN_ENTITLEMENTS = AblyPushExample/AblyPushExample.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_ASSET_PATHS = "\"AblyCocoaAPNSExample/Preview Content\""; + DEVELOPMENT_ASSET_PATHS = "\"AblyPushExample/Preview Content\""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_FILE = AblyCocoaAPNSExample/Info.plist; + INFOPLIST_FILE = AblyPushExample/Info.plist; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -350,8 +350,8 @@ "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = "io.ably.basic-apns-example"; - PRODUCT_NAME = "Push Example"; + PRODUCT_BUNDLE_IDENTIFIER = "io.ably.basic-push-example"; + PRODUCT_NAME = "Ably Push"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -361,7 +361,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 8405EE7B27F0B06800C9E461 /* Build configuration list for PBXProject "AblyCocoaAPNSExample" */ = { + 8405EE7B27F0B06800C9E461 /* Build configuration list for PBXProject "AblyPushExample" */ = { isa = XCConfigurationList; buildConfigurations = ( 8405EE8C27F0B06C00C9E461 /* Debug */, @@ -370,7 +370,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 8405EE8E27F0B06C00C9E461 /* Build configuration list for PBXNativeTarget "AblyCocoaAPNSExample" */ = { + 8405EE8E27F0B06C00C9E461 /* Build configuration list for PBXNativeTarget "AblyPushExample" */ = { isa = XCConfigurationList; buildConfigurations = ( 8405EE8F27F0B06C00C9E461 /* Debug */, diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/xcshareddata/xcschemes/AblyCocoaAPNSExample.xcscheme b/Examples/AblyPush/AblyPushExample.xcodeproj/xcshareddata/xcschemes/AblyPushExample.xcscheme similarity index 81% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/xcshareddata/xcschemes/AblyCocoaAPNSExample.xcscheme rename to Examples/AblyPush/AblyPushExample.xcodeproj/xcshareddata/xcschemes/AblyPushExample.xcscheme index 2f53a2d30..fe09cb395 100644 --- a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample.xcodeproj/xcshareddata/xcschemes/AblyCocoaAPNSExample.xcscheme +++ b/Examples/AblyPush/AblyPushExample.xcodeproj/xcshareddata/xcschemes/AblyPushExample.xcscheme @@ -15,9 +15,9 @@ + BuildableName = "Ably Push.app" + BlueprintName = "AblyPushExample" + ReferencedContainer = "container:AblyPushExample.xcodeproj"> @@ -45,9 +45,9 @@ + BuildableName = "Ably Push.app" + BlueprintName = "AblyPushExample" + ReferencedContainer = "container:AblyPushExample.xcodeproj"> @@ -62,9 +62,9 @@ + BuildableName = "Ably Push.app" + BlueprintName = "AblyPushExample" + ReferencedContainer = "container:AblyPushExample.xcodeproj"> diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift b/Examples/AblyPush/AblyPushExample/AblyHelper.swift similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyHelper.swift rename to Examples/AblyPush/AblyPushExample/AblyHelper.swift diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements b/Examples/AblyPush/AblyPushExample/AblyPushExample.entitlements similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/AblyCocoaAPNSExample.entitlements rename to Examples/AblyPush/AblyPushExample/AblyPushExample.entitlements diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/App.swift b/Examples/AblyPush/AblyPushExample/App.swift similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/App.swift rename to Examples/AblyPush/AblyPushExample/App.swift diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AccentColor.colorset/Contents.json b/Examples/AblyPush/AblyPushExample/Assets.xcassets/AccentColor.colorset/Contents.json similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AccentColor.colorset/Contents.json rename to Examples/AblyPush/AblyPushExample/Assets.xcassets/AccentColor.colorset/Contents.json diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AppIcon.appiconset/Contents.json b/Examples/AblyPush/AblyPushExample/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/AppIcon.appiconset/Contents.json rename to Examples/AblyPush/AblyPushExample/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/Contents.json b/Examples/AblyPush/AblyPushExample/Assets.xcassets/Contents.json similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Assets.xcassets/Contents.json rename to Examples/AblyPush/AblyPushExample/Assets.xcassets/Contents.json diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift b/Examples/AblyPush/AblyPushExample/ContentView.swift similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/ContentView.swift rename to Examples/AblyPush/AblyPushExample/ContentView.swift diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Info.plist b/Examples/AblyPush/AblyPushExample/Info.plist similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Info.plist rename to Examples/AblyPush/AblyPushExample/Info.plist diff --git a/Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Preview Content/Preview Assets.xcassets/Contents.json b/Examples/AblyPush/AblyPushExample/Preview Content/Preview Assets.xcassets/Contents.json similarity index 100% rename from Examples/AblyCocoaAPNSExample/AblyCocoaAPNSExample/Preview Content/Preview Assets.xcassets/Contents.json rename to Examples/AblyPush/AblyPushExample/Preview Content/Preview Assets.xcassets/Contents.json diff --git a/Examples/AblyCocoaAPNSExample/README.md b/Examples/AblyPush/README.md similarity index 100% rename from Examples/AblyCocoaAPNSExample/README.md rename to Examples/AblyPush/README.md From edbda42f93c604d0bd5cfb1a516f73168b1695e8 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 10 Apr 2022 14:28:54 +0200 Subject: [PATCH 16/18] Clarified comment about Device Details button --- Examples/AblyPush/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/AblyPush/README.md b/Examples/AblyPush/README.md index 65587ec60..b375798a1 100644 --- a/Examples/AblyPush/README.md +++ b/Examples/AblyPush/README.md @@ -5,6 +5,7 @@ You will need a real iOS device to test this functionality. - Insert it instead of an empty string in the `key` property's value inside the `AblyHelper` class. - Make sure you've selected your development team in the `Signing & Capabilities` tab of the Xcode project target settings and all the provisioning profiles created without errors. - Build and Run the app on your device. -- Hit "Activate" button, then hit "Print Token". You should see the printed value in the debug output window. You can also hit "Device Details" for additional check. +- Hit "Activate" button, then hit "Print Token". You should see the printed value in the debug output window. +- Hit "Device Details" to display Ably push device registration info after successful activation. - Go to the `Notifications` tab of the Ably's app dashboard and scroll to the `Push Inspector` section. Fill in `Title` and `Body` fields of the push notification. Then insert "basic-apns-example" in the `Client ID` field and press enter. Then hit "Push to client" button. You should now see the notification on the screen of your device. - Also you can send notifications from the app itself if you tick `Push Admin` capability in your API key settings in the app's dashboard. Just hit "Send Push" button to send a predefined push notification which is also will be displayed on your device's screen right away. You can change this behavior in the `UNUserNotificationCenterDelegate` extension for the `AblyHelper` by editing `completionHandler([.banner, .sound])` line of code. \ No newline at end of file From e1de5a8a505f6c08b2743868e0c024e9e71170e8 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 10 Apr 2022 14:34:12 +0200 Subject: [PATCH 17/18] Added `Push Notifications Setup` ably dashboard section step --- Examples/AblyPush/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/AblyPush/README.md b/Examples/AblyPush/README.md index b375798a1..0993c91f4 100644 --- a/Examples/AblyPush/README.md +++ b/Examples/AblyPush/README.md @@ -2,10 +2,11 @@ This app gives you a brief understanding of how Ably's Push Notifications work. You will need a real iOS device to test this functionality. - First, go to https://ably.com/accounts/, create an app and copy API key from API Keys tab of the app's dashboard. +- Go to the `Notifications` tab of the Ably's app dashboard and scroll to the `Push Notifications Setup` section. Press `Configure Push` and follow the instructions there. - Insert it instead of an empty string in the `key` property's value inside the `AblyHelper` class. - Make sure you've selected your development team in the `Signing & Capabilities` tab of the Xcode project target settings and all the provisioning profiles created without errors. - Build and Run the app on your device. - Hit "Activate" button, then hit "Print Token". You should see the printed value in the debug output window. - Hit "Device Details" to display Ably push device registration info after successful activation. -- Go to the `Notifications` tab of the Ably's app dashboard and scroll to the `Push Inspector` section. Fill in `Title` and `Body` fields of the push notification. Then insert "basic-apns-example" in the `Client ID` field and press enter. Then hit "Push to client" button. You should now see the notification on the screen of your device. +- Go to the `Notifications` tab of the Ably's app dashboard again and scroll to the `Push Inspector` section. Fill in `Title` and `Body` fields of the push notification. Then insert "basic-apns-example" in the `Client ID` field and press enter. Then hit "Push to client" button. You should now see the notification on the screen of your device. - Also you can send notifications from the app itself if you tick `Push Admin` capability in your API key settings in the app's dashboard. Just hit "Send Push" button to send a predefined push notification which is also will be displayed on your device's screen right away. You can change this behavior in the `UNUserNotificationCenterDelegate` extension for the `AblyHelper` by editing `completionHandler([.banner, .sound])` line of code. \ No newline at end of file From bb4cacf858ce690afaa8eb285ec9600225e24632 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 10 Apr 2022 15:06:16 +0200 Subject: [PATCH 18/18] Fixed CI step for example project --- .github/workflows/integration-test-iOS14_4.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-test-iOS14_4.yaml b/.github/workflows/integration-test-iOS14_4.yaml index 5835449bc..961ea1226 100644 --- a/.github/workflows/integration-test-iOS14_4.yaml +++ b/.github/workflows/integration-test-iOS14_4.yaml @@ -65,9 +65,9 @@ jobs: bundle exec fastlane scan -s Tests --output-directory "fastlane/test_output/examples/test_iOS14_4" - name: Build APNS Example Project - working-directory: ./Examples/AblyCocoaAPNSExample + working-directory: ./Examples/AblyPush run: | - xcodebuild build -scheme "AblyCocoaAPNSExample" -destination "platform=iOS Simulator,name=iPhone 12" -configuration "Debug" + xcodebuild build -scheme "AblyPushExample" -destination "platform=iOS Simulator,name=iPhone 12" -configuration "Debug" - name: Xcodebuild Logs Artifact if: always()