Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

iOS console : notifications (WIP)

William Balcaendc76480cec52
diff --git a/console/iOS/NotificationExtension/Info.plist b/console/iOS/NotificationExtension/Info.plist
new file mode 100644
index 000000000..36f5c9148
--- /dev/null
+++ b/console/iOS/NotificationExtension/Info.plist
@@ -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>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>NotificationExtension</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>XPC!</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>
diff --git a/console/iOS/NotificationExtension/NotificationService.swift b/console/iOS/NotificationExtension/NotificationService.swift
new file mode 100644
index 000000000..a423640f5
--- /dev/null
+++ b/console/iOS/NotificationExtension/NotificationService.swift
@@ -0,0 +1,87 @@
+//
+// NotificationService.swift
+// NotificationExtension
+//
+// Created by William Balcaen on 16/03/17.
+// Copyright © 2017 TInSys. All rights reserved.
+//
+
+import UserNotifications
+
+class NotificationService: UNNotificationServiceExtension {
+
+ 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)
+ print("NotifExtension Change content ",bestAttemptContent?.userInfo ?? "")
+ if let bestAttemptContent = bestAttemptContent {
+ // Call backend to get payload and adapt title, body and actions
+ bestAttemptContent.title = "You received an alarm from blok61 :"
+ bestAttemptContent.body = "payload received from backend..."
+ guard let tkurlRequest = URL(string: "http://192.168.99.100:8080/auth/realms/blok61/protocol/openid-connect/token") else { return }
+ let tkRequest = NSMutableURLRequest(url: tkurlRequest)
+ tkRequest.addValue("application/x-www-form-urlencoded", forHTTPHeaderField:"Content-Type");
+ tkRequest.httpMethod = "POST"
+ let postString = "grant_type=refresh_token&refresh_token=eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJDZXZKWnZHVmdKUWRyZTlGU1kzelF6NWZDZ080WW5iaHd1Ukg2WW9yVkZnIn0.eyJqdGkiOiIzOGI5YTQxOC1hNTZkLTQ1NDYtOTBkOS02OWY0NWEzZWM3ZGUiLCJleHAiOjAsIm5iZiI6MCwiaWF0IjoxNDg5NjcwNjYzLCJpc3MiOiJodHRwOi8vMTkyLjE2OC45OS4xMDA6ODA4MC9hdXRoL3JlYWxtcy9ibG9rNjEiLCJhdWQiOiJvcGVucmVtb3RlIiwic3ViIjoiZTk2M2Y3ZWYtNWUyMy00Njk1LWE5M2QtOTU3Mjk0ODYwM2MxIiwidHlwIjoiT2ZmbGluZSIsImF6cCI6Im9wZW5yZW1vdGUiLCJub25jZSI6IjQ2Nzg3MThlLTdhMGUtNDliNy1hNDQyLTA1ODk2YmFkY2I0YiIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6ImU5YmJiODlkLTk2ZDUtNDM0Ny1hMzVhLTFmZjM0OTRmNjRlNCIsImNsaWVudF9zZXNzaW9uIjoiMTliODY0NTAtYWEzMS00OGNlLWE4ODEtMzliNjM0NDkzOThjIiwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJvcGVucmVtb3RlIjp7InJvbGVzIjpbIndyaXRlOmFzc2V0cyIsInJlYWQ6bWFwIiwicmVhZDphc3NldHMiLCJ3cml0ZTp1c2VyIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50Iiwidmlldy1wcm9maWxlIl19fX0.APnuPAlcyEnGYlOIX8W4znbJHhc-HyNc8tmKrsqVkkudf0Y3Dspgjjc3z907hBW0K_Lh0CXtWMMulZk-AcbTohNq3pnnohNsGEfXKuqWeIRjJwiArItwo5u5XgTveLWn7fPTMl8IplGqVptUCdBex1QKmMa_PfFLRLb9Xjh4XI5MKGp1qy_vL8NH1xhKud1quyTLivxGrZpsC8Dyln2VUGbD5nFCYlzVv4zqTk0K3laaW52v9y5AAp2iYLgjoxrW-WBDExfTWdz9TQ3t5q35_GnyyzlE-uBYvppKMxZ4Hb0YkAslEvKYgUnplRx9UD9EBw8auG1fRQ4e1C4_4PqoWw&client_id=openremote"
+ tkRequest.httpBody = postString.data(using: .utf8)
+ let sessionConfiguration = URLSessionConfiguration.default
+ let session = URLSession(configuration: sessionConfiguration)
+ let req = session.dataTask(with: tkRequest as URLRequest, completionHandler: { (data, response, error) in
+ if (data != nil){
+ do {
+ let jsonDictionnary: Dictionary = try JSONSerialization.jsonObject(with: data!, options: []) as! [String:Any]
+ if ((jsonDictionnary["access_token"]) != nil) {
+ guard let urlRequest = URL(string: "http://192.168.99.100:8080/blok61/asset") else { return }
+ let request = NSMutableURLRequest(url: urlRequest)
+ request.addValue(String(format:"Bearer %@", jsonDictionnary["access_token"] as! String), forHTTPHeaderField: "Authorization")
+ let sessionConfiguration = URLSessionConfiguration.default
+ let session = URLSession(configuration: sessionConfiguration)
+ let reqDataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
+ DispatchQueue.main.async {
+ if (error != nil) {
+ bestAttemptContent.body = error.debugDescription
+ } else {
+ bestAttemptContent.body = String(data: data!, encoding: .utf8)!
+ contentHandler(bestAttemptContent)
+ }
+ }
+ })
+ reqDataTask.resume()
+ } else {
+ if let httpResponse = response as? HTTPURLResponse {
+ let error = NSError(domain: "", code: httpResponse.statusCode, userInfo: jsonDictionnary)
+ bestAttemptContent.body = error.debugDescription
+ contentHandler(bestAttemptContent)
+ } else {
+ let error = NSError(domain: "", code: 0, userInfo: jsonDictionnary)
+ bestAttemptContent.body = error.debugDescription
+ contentHandler(bestAttemptContent)
+ }
+ }
+ }
+ catch let error as NSError {
+ bestAttemptContent.body = error.debugDescription
+ contentHandler(bestAttemptContent)
+ }
+ } else {
+ bestAttemptContent.body = error.debugDescription
+ contentHandler(bestAttemptContent)
+ }
+ })
+ req.resume()
+
+ }
+ }
+
+ override func serviceExtensionTimeWillExpire() {
+ // Called just before the extension will be terminated by the system.
+ // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
+ print("NotifExtension Time has expired")
+ if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
+ contentHandler(bestAttemptContent)
+ }
+ }
+}
diff --git a/console/iOS/console.xcodeproj/project.pbxproj b/console/iOS/console.xcodeproj/project.pbxproj
index 0756f68ff..011ac49b0 100644
--- a/console/iOS/console.xcodeproj/project.pbxproj
+++ b/console/iOS/console.xcodeproj/project.pbxproj
@@ -18,8 +18,20 @@
FAA226B81E71563F009A8FEC /* TokenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA226B71E71563F009A8FEC /* TokenManager.swift */; };
FAA226BA1E715ED6009A8FEC /* TokenManagerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = FAA226B91E715ED6009A8FEC /* TokenManagerView.xib */; };
FAA226BC1E7163D9009A8FEC /* TokenManagerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA226BB1E7163D9009A8FEC /* TokenManagerViewController.swift */; };
+ FAFF2E2D1E7A95120076BDE3 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAFF2E2C1E7A95120076BDE3 /* NotificationService.swift */; };
+ FAFF2E311E7A95120076BDE3 /* NotificationExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = FAFF2E2A1E7A95120076BDE3 /* NotificationExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
+/* Begin PBXContainerItemProxy section */
+ FAFF2E2F1E7A95120076BDE3 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = FA1D73D61E53374E00F6240A /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = FAFF2E291E7A95120076BDE3;
+ remoteInfo = NotificationExtension;
+ };
+/* End PBXContainerItemProxy section */
+
/* Begin PBXCopyFilesBuildPhase section */
FAAFD0C61E78115700F01155 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
@@ -27,6 +39,7 @@
dstPath = "";
dstSubfolderSpec = 13;
files = (
+ FAFF2E311E7A95120076BDE3 /* NotificationExtension.appex in Embed App Extensions */,
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
@@ -50,8 +63,11 @@
FAA226B91E715ED6009A8FEC /* TokenManagerView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TokenManagerView.xib; sourceTree = "<group>"; };
FAA226BB1E7163D9009A8FEC /* TokenManagerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenManagerViewController.swift; sourceTree = "<group>"; };
FAAFD0B41E77EB6E00F01155 /* console.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = console.entitlements; sourceTree = "<group>"; };
- FAAFD0BD1E78115700F01155 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
- FAAFD0BF1E78115700F01155 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+ FAFF2E2A1E7A95120076BDE3 /* NotificationExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
+ FAFF2E2C1E7A95120076BDE3 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
+ FAFF2E2E1E7A95120076BDE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+ FAFF2E3A1E7AD2080076BDE3 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
+ FAFF2E3C1E7AD2080076BDE3 /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -63,6 +79,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ FAFF2E271E7A95120076BDE3 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
@@ -79,6 +102,8 @@
isa = PBXGroup;
children = (
D4964874264350BC5EAC8F84 /* Pods_console.framework */,
+ FAFF2E3A1E7AD2080076BDE3 /* UserNotifications.framework */,
+ FAFF2E3C1E7AD2080076BDE3 /* UserNotificationsUI.framework */,
);
name = Frameworks;
sourceTree = "<group>";
@@ -87,7 +112,7 @@
isa = PBXGroup;
children = (
FA1D73E01E53374E00F6240A /* console */,
- FAAFD0BC1E78115700F01155 /* consoleNSE */,
+ FAFF2E2B1E7A95120076BDE3 /* NotificationExtension */,
FA1D73DF1E53374E00F6240A /* Products */,
B5A9A3A4436D6649979AAD5D /* Pods */,
D99D42C10629DD05EE566F2F /* Frameworks */,
@@ -98,6 +123,7 @@
isa = PBXGroup;
children = (
FA1D73DE1E53374E00F6240A /* console.app */,
+ FAFF2E2A1E7A95120076BDE3 /* NotificationExtension.appex */,
);
name = Products;
sourceTree = "<group>";
@@ -129,13 +155,13 @@
name = utils;
sourceTree = "<group>";
};
- FAAFD0BC1E78115700F01155 /* consoleNSE */ = {
+ FAFF2E2B1E7A95120076BDE3 /* NotificationExtension */ = {
isa = PBXGroup;
children = (
- FAAFD0BD1E78115700F01155 /* NotificationService.swift */,
- FAAFD0BF1E78115700F01155 /* Info.plist */,
+ FAFF2E2C1E7A95120076BDE3 /* NotificationService.swift */,
+ FAFF2E2E1E7A95120076BDE3 /* Info.plist */,
);
- path = consoleNSE;
+ path = NotificationExtension;
sourceTree = "<group>";
};
/* End PBXGroup section */
@@ -156,12 +182,30 @@
buildRules = (
);
dependencies = (
+ FAFF2E301E7A95120076BDE3 /* PBXTargetDependency */,
);
name = console;
productName = console;
productReference = FA1D73DE1E53374E00F6240A /* console.app */;
productType = "com.apple.product-type.application";
};
+ FAFF2E291E7A95120076BDE3 /* NotificationExtension */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = FAFF2E321E7A95120076BDE3 /* Build configuration list for PBXNativeTarget "NotificationExtension" */;
+ buildPhases = (
+ FAFF2E261E7A95120076BDE3 /* Sources */,
+ FAFF2E271E7A95120076BDE3 /* Frameworks */,
+ FAFF2E281E7A95120076BDE3 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = NotificationExtension;
+ productName = NotificationExtension;
+ productReference = FAFF2E2A1E7A95120076BDE3 /* NotificationExtension.appex */;
+ productType = "com.apple.product-type.app-extension";
+ };
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@@ -174,7 +218,6 @@
TargetAttributes = {
FA1D73DD1E53374E00F6240A = {
CreatedOnToolsVersion = 8.2.1;
- DevelopmentTeam = 4W5599S8TP;
LastSwiftMigration = 0820;
ProvisioningStyle = Automatic;
SystemCapabilities = {
@@ -186,6 +229,10 @@
};
};
};
+ FAFF2E291E7A95120076BDE3 = {
+ CreatedOnToolsVersion = 8.2.1;
+ ProvisioningStyle = Automatic;
+ };
};
};
buildConfigurationList = FA1D73D91E53374E00F6240A /* Build configuration list for PBXProject "console" */;
@@ -202,6 +249,7 @@
projectRoot = "";
targets = (
FA1D73DD1E53374E00F6240A /* console */,
+ FAFF2E291E7A95120076BDE3 /* NotificationExtension */,
);
};
/* End PBXProject section */
@@ -218,6 +266,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ FAFF2E281E7A95120076BDE3 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
@@ -282,8 +337,24 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ FAFF2E261E7A95120076BDE3 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ FAFF2E2D1E7A95120076BDE3 /* NotificationService.swift in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXSourcesBuildPhase section */
+/* Begin PBXTargetDependency section */
+ FAFF2E301E7A95120076BDE3 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = FAFF2E291E7A95120076BDE3 /* NotificationExtension */;
+ targetProxy = FAFF2E2F1E7A95120076BDE3 /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
/* Begin PBXVariantGroup section */
FA1D73E51E53374E00F6240A /* Main.storyboard */ = {
isa = PBXVariantGroup;
@@ -404,6 +475,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = console/console.entitlements;
+ DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = console/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -420,6 +492,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = console/console.entitlements;
+ DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = console/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -429,6 +502,32 @@
};
name = Release;
};
+ FAFF2E331E7A95120076BDE3 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ DEVELOPMENT_TEAM = "";
+ INFOPLIST_FILE = NotificationExtension/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = org.openremote.console.NotificationExtension;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SKIP_INSTALL = YES;
+ SWIFT_VERSION = 3.0;
+ };
+ name = Debug;
+ };
+ FAFF2E341E7A95120076BDE3 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ DEVELOPMENT_TEAM = "";
+ INFOPLIST_FILE = NotificationExtension/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = org.openremote.console.NotificationExtension;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SKIP_INSTALL = YES;
+ SWIFT_VERSION = 3.0;
+ };
+ name = Release;
+ };
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
@@ -450,6 +549,14 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
+ FAFF2E321E7A95120076BDE3 /* Build configuration list for PBXNativeTarget "NotificationExtension" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ FAFF2E331E7A95120076BDE3 /* Debug */,
+ FAFF2E341E7A95120076BDE3 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
/* End XCConfigurationList section */
};
rootObject = FA1D73D61E53374E00F6240A /* Project object */;
diff --git a/console/iOS/console.xcodeproj/xcuserdata/wbalcaen.xcuserdatad/xcschemes/NotificationExtension.xcscheme b/console/iOS/console.xcodeproj/xcuserdata/wbalcaen.xcuserdatad/xcschemes/NotificationExtension.xcscheme
new file mode 100644
index 000000000..5c8f29950
--- /dev/null
+++ b/console/iOS/console.xcodeproj/xcuserdata/wbalcaen.xcuserdatad/xcschemes/NotificationExtension.xcscheme
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0820"
+ wasCreatedForAppExtension = "YES"
+ version = "2.0">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "FAFF2E291E7A95120076BDE3"
+ BuildableName = "NotificationExtension.appex"
+ BlueprintName = "NotificationExtension"
+ ReferencedContainer = "container:console.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "FA1D73DD1E53374E00F6240A"
+ BuildableName = "console.app"
+ BlueprintName = "console"
+ ReferencedContainer = "container:console.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "FAFF2E291E7A95120076BDE3"
+ BuildableName = "NotificationExtension.appex"
+ BlueprintName = "NotificationExtension"
+ ReferencedContainer = "container:console.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = ""
+ selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES"
+ launchAutomaticallySubstyle = "2">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "FA1D73DD1E53374E00F6240A"
+ BuildableName = "console.app"
+ BlueprintName = "console"
+ ReferencedContainer = "container:console.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES"
+ launchAutomaticallySubstyle = "2">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "FA1D73DD1E53374E00F6240A"
+ BuildableName = "console.app"
+ BlueprintName = "console"
+ ReferencedContainer = "container:console.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/console/iOS/console.xcodeproj/xcuserdata/wbalcaen.xcuserdatad/xcschemes/xcschememanagement.plist b/console/iOS/console.xcodeproj/xcuserdata/wbalcaen.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 000000000..34c0146ff
--- /dev/null
+++ b/console/iOS/console.xcodeproj/xcuserdata/wbalcaen.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,47 @@
+<?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>SchemeUserState</key>
+ <dict>
+ <key>NotificationExtension.xcscheme</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>5</integer>
+ </dict>
+ <key>console.xcscheme</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>0</integer>
+ </dict>
+ </dict>
+ <key>SuppressBuildableAutocreation</key>
+ <dict>
+ <key>FA1D73DD1E53374E00F6240A</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ <key>FA6985B01E7A84BD005BE296</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ <key>FAAFD0BA1E78115700F01155</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ <key>FAFF2E291E7A95120076BDE3</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ <key>FAFF2E381E7AD2080076BDE3</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ </dict>
+</dict>
+</plist>
diff --git a/console/iOS/console/AppDelegate.swift b/console/iOS/console/AppDelegate.swift
index 616208fae..d811fd7ae 100644
--- a/console/iOS/console/AppDelegate.swift
+++ b/console/iOS/console/AppDelegate.swift
@@ -20,16 +20,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var isGrantedNotificationAccess:Bool = false
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
- // allows to catch all request and add custom headers (works only with UIWebView not WKWebView).
- // For iOS 10 display notification (sent via APNS)
+ setActions()
UNUserNotificationCenter.current().delegate = self
-
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
- // For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self
FIRApp.configure()
@@ -37,22 +34,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
application.registerForRemoteNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil)
- UNUserNotificationCenter.current().requestAuthorization(
- options: [.alert,.sound,.badge],
- completionHandler: { (granted,error) in
- self.isGrantedNotificationAccess = granted
- let ok = UNNotificationAction(identifier: "OpenApp",
- title: "Open App", options: [.foreground])
-
- let cancel = UNNotificationAction(identifier: "ResetAlarm",
- title: "Reset Alarm",
- options: [.destructive])
-
- let category = UNNotificationCategory(identifier: "message", actions: [ok, cancel], intentIdentifiers: [], options: [])
-
- UNUserNotificationCenter.current().setNotificationCategories([category])
- }
- )
+
return true
}
@@ -86,20 +68,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
- if let messageID = userInfo[gcmMessageIDKey] {
- print("Message ID: \(messageID)")
- }
-
// Print full message.
print(userInfo)
- self.scheduleLocalNotification()
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
- self.scheduleLocalNotification()
+ //self.scheduleLocalNotification()
+ print(userInfo)
completionHandler(UIBackgroundFetchResult.noData)
}
+ //MARK : - UNUserNotificationCenterDelegate
+
+ func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
+ completionHandler([.alert, .sound])
+ }
+
+ func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
+ print("Action asked : ",response.actionIdentifier)
+ }
+
+
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if (self.currentAuthorizationFlow?.resumeAuthorizationFlow(with: url))! {
self.currentAuthorizationFlow = nil
@@ -108,9 +97,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
return false
}
- func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
- print("Action asked : ",response.actionIdentifier)
- }
func connectToFcm()
{
@@ -121,7 +107,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
else
{
- print("Connected to FCM. Token is ",FIRInstanceID.instanceID().token()! as String)
+ if let token = FIRInstanceID.instanceID().token() {
+ print("Connected to FCM. Token is ",token as String)
+ } else {
+ print("Connected to FCM. Token is currently nil")
+ }
}
}
}
@@ -136,32 +126,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
connectToFcm()
}
- private func scheduleLocalNotification() {
- // Create Notification Content
- let notificationContent = UNMutableNotificationContent()
- // Configure Notification Content
- notificationContent.title = "Cocoacasts"
- notificationContent.subtitle = "Local Notifications"
- notificationContent.body = "In this tutorial, you learn how to schedule local notifications with the User Notifications framework."
- notificationContent.categoryIdentifier = "message"
+
+}
- // Add Trigger
- let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 10.0, repeats: false)
-
- // Create Notification Request
- let notificationRequest = UNNotificationRequest(identifier: "cocoacasts_local_notification", content: notificationContent, trigger: notificationTrigger)
-
- // Add Request to User Notification Center
- UNUserNotificationCenter.current().add(notificationRequest) { (error) in
- if let error = error {
- print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
- }
- }
- }
+func setActions() {
+ let openApp = UNNotificationAction(
+ identifier: "openApp",
+ title: "Open Application",
+ options : [.foreground]
+ )
+ let dismiss = UNNotificationAction(
+ identifier: "dismiss",
+ title: "Dismiss",
+ options: [.destructive]
+ )
+ let category = UNNotificationCategory(
+ identifier: "blok61Notification",
+ actions: [openApp, dismiss],
+ intentIdentifiers: []
+ )
+
+ UNUserNotificationCenter.current().setNotificationCategories([category])
}
-// [START ios_10_data_message_handling]
extension AppDelegate : FIRMessagingDelegate {
// Receive data message on iOS 10 devices while app is in the foreground.
func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {