Skip to content

armgit / core

Public Imported from GitHub
0

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

Updated to work with relative urls in console app config

Michael Rademaker6261a067feb0
diff --git a/console/iOS/GenericApp/GenericApp.xcodeproj/project.pbxproj b/console/iOS/GenericApp/GenericApp.xcodeproj/project.pbxproj
index 93653527e..69c4bc798 100644
--- a/console/iOS/GenericApp/GenericApp.xcodeproj/project.pbxproj
+++ b/console/iOS/GenericApp/GenericApp.xcodeproj/project.pbxproj
@@ -13,6 +13,7 @@
4CEDA25D25405B1E00C47E3B /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4CEDA25C25405B1E00C47E3B /* GoogleService-Info.plist */; };
4CEDA2A7254074D100C47E3B /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4CEDA2A6254074D100C47E3B /* Storyboard.storyboard */; };
4CEDA2CE254075D400C47E3B /* SplashViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEDA2CD254075D400C47E3B /* SplashViewController.swift */; };
+ 4CF3439127A13F2200EB5A0E /* String+Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF3439027A13F2200EB5A0E /* String+Utils.swift */; };
5952998DA2B50AFF73DDCAE1 /* Pods_NotificationService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570B5A477F4AA747A62A45EF /* Pods_NotificationService.framework */; };
756FA8BF24545CB0CC18CA6E /* Pods_GenericApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E012F268F107177E6B242E8 /* Pods_GenericApp.framework */; };
878D2D0D249A490300011484 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 878D2D0C249A490300011484 /* AppDelegate.swift */; };
@@ -58,6 +59,7 @@
4CEDA25C25405B1E00C47E3B /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
4CEDA2A6254074D100C47E3B /* Storyboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = "<group>"; };
4CEDA2CD254075D400C47E3B /* SplashViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashViewController.swift; sourceTree = "<group>"; };
+ 4CF3439027A13F2200EB5A0E /* String+Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Utils.swift"; sourceTree = "<group>"; };
4E012F268F107177E6B242E8 /* Pods_GenericApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GenericApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
570B5A477F4AA747A62A45EF /* Pods_NotificationService.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NotificationService.framework; sourceTree = BUILT_PRODUCTS_DIR; };
878D2D09249A490300011484 /* OpenRemote.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenRemote.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -96,6 +98,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
+ 4CF3438F27A13F0400EB5A0E /* Utils */ = {
+ isa = PBXGroup;
+ children = (
+ 4CF3439027A13F2200EB5A0E /* String+Utils.swift */,
+ );
+ path = Utils;
+ sourceTree = "<group>";
+ };
6E621588C821060939F236DC /* Pods */ = {
isa = PBXGroup;
children = (
@@ -133,6 +143,7 @@
4C38E9C02548089A00E381C6 /* OpenRemote.entitlements */,
4CEDA25C25405B1E00C47E3B /* GoogleService-Info.plist */,
878D2D34249A50E500011484 /* UI */,
+ 4CF3438F27A13F0400EB5A0E /* Utils */,
878D2D0C249A490300011484 /* AppDelegate.swift */,
878D2D12249A490400011484 /* Assets.xcassets */,
878D2D17249A490400011484 /* LaunchScreen.storyboard */,
@@ -352,6 +363,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 4CF3439127A13F2200EB5A0E /* String+Utils.swift in Sources */,
4C81AA642546B251006ED5DD /* ProjectViewController.swift in Sources */,
878D2D0D249A490300011484 /* AppDelegate.swift in Sources */,
4CEDA2CE254075D400C47E3B /* SplashViewController.swift in Sources */,
@@ -508,11 +520,11 @@
isa = XCBuildConfiguration;
baseConfigurationReference = A994B3D3E3853BA4D16AA5A8 /* Pods-GenericApp.debug.xcconfig */;
buildSettings = {
- ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
+ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = GenericApp/OpenRemote.entitlements;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 27;
+ CURRENT_PROJECT_VERSION = 28;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 4AC88KZHJZ;
ENABLE_PREVIEWS = YES;
@@ -522,7 +534,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
- MARKETING_VERSION = 1.0.4;
+ MARKETING_VERSION = 1.0.5;
PRODUCT_BUNDLE_IDENTIFIER = io.openremote.app;
PRODUCT_NAME = OpenRemote;
SWIFT_VERSION = 5.0;
@@ -534,11 +546,11 @@
isa = XCBuildConfiguration;
baseConfigurationReference = D61E1E0434CC1446EAF20BA0 /* Pods-GenericApp.release.xcconfig */;
buildSettings = {
- ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
+ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = GenericApp/OpenRemote.entitlements;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 27;
+ CURRENT_PROJECT_VERSION = 28;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 4AC88KZHJZ;
ENABLE_PREVIEWS = YES;
@@ -548,7 +560,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
- MARKETING_VERSION = 1.0.4;
+ MARKETING_VERSION = 1.0.5;
PRODUCT_BUNDLE_IDENTIFIER = io.openremote.app;
PRODUCT_NAME = OpenRemote;
SWIFT_VERSION = 5.0;
@@ -560,6 +572,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3B0E05618605D241D5A82AA3 /* Pods-NotificationService.debug.xcconfig */;
buildSettings = {
+ APPLICATION_EXTENSION_API_ONLY = YES;
CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 27;
@@ -584,6 +597,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 46FD90D41833A0E2C4C7DDA6 /* Pods-NotificationService.release.xcconfig */;
buildSettings = {
+ APPLICATION_EXTENSION_API_ONLY = YES;
CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 27;
diff --git a/console/iOS/GenericApp/GenericApp/Storyboard.storyboard b/console/iOS/GenericApp/GenericApp/Storyboard.storyboard
index aa108bab0..66dfabc80 100644
--- a/console/iOS/GenericApp/GenericApp/Storyboard.storyboard
+++ b/console/iOS/GenericApp/GenericApp/Storyboard.storyboard
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="oDU-zF-Uvs">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="oDU-zF-Uvs">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
- <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -55,7 +55,7 @@
<constraint firstAttribute="height" constant="40" id="nJi-N3-4Su"/>
</constraints>
<userDefinedRuntimeAttributes>
- <userDefinedRuntimeAttribute type="string" keyPath="setPlaceholderText" value="Project"/>
+ <userDefinedRuntimeAttribute type="string" keyPath="setPlaceholderText" value="Project domain"/>
</userDefinedRuntimeAttributes>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2fd-Z9-umb" customClass="ORTextInput" customModule="ORLib">
diff --git a/console/iOS/GenericApp/GenericApp/UI/ProjectViewController.swift b/console/iOS/GenericApp/GenericApp/UI/ProjectViewController.swift
index 7a0e483ce..804152afa 100644
--- a/console/iOS/GenericApp/GenericApp/UI/ProjectViewController.swift
+++ b/console/iOS/GenericApp/GenericApp/UI/ProjectViewController.swift
@@ -15,6 +15,7 @@ class ProjectViewController: UIViewController {
var projectName: String?
var realmName: String?
var appconfig: ORAppConfig?
+ var host: String?
@IBOutlet weak var projectTextInput: ORTextInput!
@IBOutlet weak var realmTextInput: ORTextInput!
@@ -70,12 +71,15 @@ extension ProjectViewController: UITextFieldDelegate {
}
fileprivate func requestAppConfig(_ project: String, _ realm: String) {
- let apiManager = ApiManager(baseUrl: "https://\(project).openremote.io/api/\(realm)")
+ host = project.isUrl() ? project : "https://\(project).openremote.io/"
+ let url = project.isUrl() ? project.appending("/api/\(realm)") : "https://\(project).openremote.io/api/\(realm)"
+
+ let apiManager = ApiManager(baseUrl: url)
apiManager.getAppConfig(callback: { statusCode, orAppConfig, error in
DispatchQueue.main.async {
if statusCode == 200 && error == nil {
let userDefaults = UserDefaults(suiteName: DefaultsKey.groupEntitlement)
- userDefaults?.set(project, forKey: DefaultsKey.projectKey)
+ userDefaults?.set(self.host, forKey: DefaultsKey.hostKey)
userDefaults?.set(realm, forKey: DefaultsKey.realmKey)
self.appconfig = orAppConfig
diff --git a/console/iOS/GenericApp/GenericApp/UI/SplashViewController.swift b/console/iOS/GenericApp/GenericApp/UI/SplashViewController.swift
index 53107cd1e..5e51215ed 100644
--- a/console/iOS/GenericApp/GenericApp/UI/SplashViewController.swift
+++ b/console/iOS/GenericApp/GenericApp/UI/SplashViewController.swift
@@ -12,20 +12,21 @@ import ORLib
class SplashViewController: UIViewController {
var appconfig: ORAppConfig?
+ var host: String?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let userDefaults = UserDefaults(suiteName: DefaultsKey.groupEntitlement),
- let project = userDefaults.string(forKey: DefaultsKey.projectKey),
+ let savedHost = userDefaults.string(forKey: DefaultsKey.hostKey),
let realm = userDefaults.string(forKey: DefaultsKey.realmKey) {
- let apiManager = ApiManager(baseUrl: "https://\(project).openremote.io/api/\(realm)")
+ host = savedHost
+ let url = host!.appending("/api/\(realm)")
+
+ let apiManager = ApiManager(baseUrl: url)
apiManager.getAppConfig(callback: { statusCode, orAppConfig, error in
DispatchQueue.main.async {
if statusCode == 200 && error == nil {
- let userDefaults = UserDefaults(suiteName: DefaultsKey.groupEntitlement)
- userDefaults?.set(project, forKey: DefaultsKey.projectKey)
- userDefaults?.set(realm, forKey: DefaultsKey.realmKey)
self.appconfig = orAppConfig
self.performSegue(withIdentifier: "goToWebView", sender: self)
@@ -43,6 +44,7 @@ class SplashViewController: UIViewController {
if segue.identifier == "goToWebView" {
let orViewController = segue.destination as! ORViewcontroller
orViewController.appConfig = self.appconfig
+ orViewController.baseUrl = host
}
}
}
diff --git a/console/iOS/GenericApp/GenericApp/Utils/String+Utils.swift b/console/iOS/GenericApp/GenericApp/Utils/String+Utils.swift
new file mode 100644
index 000000000..99aac32f1
--- /dev/null
+++ b/console/iOS/GenericApp/GenericApp/Utils/String+Utils.swift
@@ -0,0 +1,19 @@
+//
+// String+Utils.swift
+// GenericApp
+//
+// Created by Michael Rademaker on 26/01/2022.
+// Copyright © 2022 OpenRemote. All rights reserved.
+//
+
+import Foundation
+import UIKit
+
+extension String {
+ func isUrl () -> Bool {
+ if let url = NSURL(string: self) {
+ return UIApplication.shared.canOpenURL(url as URL)
+ }
+ return false
+ }
+}
diff --git a/console/iOS/GenericApp/Podfile b/console/iOS/GenericApp/Podfile
index edfaaa85e..436ca7da7 100644
--- a/console/iOS/GenericApp/Podfile
+++ b/console/iOS/GenericApp/Podfile
@@ -20,10 +20,11 @@ target 'GenericApp' do
end
target 'NotificationService' do
+ project 'GenericApp'
+ shared_pods
pod 'Firebase/Messaging'
pod 'Firebase/Crashlytics'
pod 'Firebase/Analytics'
- project 'GenericApp'
end
target 'ORLib' do
diff --git a/console/iOS/ORLib/ORLib/Models/ORAppConfig.swift b/console/iOS/ORLib/ORLib/Models/ORAppConfig.swift
index 99f4c9dd6..d42c396e0 100644
--- a/console/iOS/ORLib/ORLib/Models/ORAppConfig.swift
+++ b/console/iOS/ORLib/ORLib/Models/ORAppConfig.swift
@@ -9,13 +9,11 @@
import UIKit
public struct ORAppConfig: Codable {
- let id: Int32
let realm: String
- let initialUrl: String
+ let initialUrl: String?
let url: String
let menuEnabled: Bool
let menuPosition: String?
- let menuImage: String?
let primaryColor: String?
let secondaryColor: String?
let links: [ORLinkConfig]?
diff --git a/console/iOS/ORLib/ORLib/Network/ApiManager.swift b/console/iOS/ORLib/ORLib/Network/ApiManager.swift
index 33704c881..69bf9ff90 100644
--- a/console/iOS/ORLib/ORLib/Network/ApiManager.swift
+++ b/console/iOS/ORLib/ORLib/Network/ApiManager.swift
@@ -87,6 +87,13 @@ public class ApiManager: NSObject {
callback?(httpStatusCode, nil, error);
return
}
+ do {
+ let i = try self.decoder.decode(T.self, from: responseData)
+ } catch {
+ print("Unexpected error: \(error).")
+ }
+
+
guard let responseModel = try? self.decoder.decode(T.self, from: responseData) else {
print("Couldn't parse response: \(String(data: responseData, encoding: .utf8)!)")
diff --git a/console/iOS/ORLib/ORLib/UI/ORViewController.swift b/console/iOS/ORLib/ORLib/UI/ORViewController.swift
index fa2c09722..8ad32dba2 100644
--- a/console/iOS/ORLib/ORLib/UI/ORViewController.swift
+++ b/console/iOS/ORLib/ORLib/UI/ORViewController.swift
@@ -39,6 +39,8 @@ open class ORViewcontroller : UIViewController {
public var pushProvider: PushNotificationProvider?
public var storageProvider: StorageProvider?
public var qrProvider: QrScannerProvider?
+
+ public var baseUrl: String?
var popoverOptions: [PopoverOption]?
@@ -51,7 +53,11 @@ open class ORViewcontroller : UIViewController {
open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let applicationConfig = appConfig {
- loadURL(url: URL(string: applicationConfig.initialUrl.stringByURLEncoding()!)!)
+ var url = applicationConfig.initialUrl ?? applicationConfig.url
+ if !url.starts(with: "http") {
+ url = baseUrl!.appending(url)
+ }
+ loadURL(url: URL(string: url.stringByURLEncoding()!)!)
}
}
@@ -217,7 +223,11 @@ open class ORViewcontroller : UIViewController {
self.present(alertView, animated: true, completion: nil)
if let applicationConfig = appConfig {
- self.myWebView?.load(URLRequest(url: URL(string: applicationConfig.url.stringByURLEncoding()!)!))
+ var url = applicationConfig.url
+ if !url.starts(with: "http") {
+ url = baseUrl!.appending(url)
+ }
+ self.myWebView?.load(URLRequest(url: URL(string: url.stringByURLEncoding()!)!))
}
}
@@ -414,7 +424,11 @@ extension ORViewcontroller: WKNavigationDelegate {
}
} else {
if let config = appConfig, let button = menuButton {
- if config.url.stringByURLEncoding() == navigationAction.request.url?.absoluteString {
+ var url = config.url
+ if !url.starts(with: "http") {
+ url = baseUrl!.appending(url)
+ }
+ if url == navigationAction.request.url?.absoluteString {
button.isHidden = false
}
}
diff --git a/console/iOS/ORLib/ORLib/Utils/Constants.swift b/console/iOS/ORLib/ORLib/Utils/Constants.swift
index d7726b7a9..4c8bd3038 100644
--- a/console/iOS/ORLib/ORLib/Utils/Constants.swift
+++ b/console/iOS/ORLib/ORLib/Utils/Constants.swift
@@ -24,6 +24,7 @@ import UIKit
public enum DefaultsKey {
public static var groupEntitlement = "group.io.openremote.app"
public static let projectKey = "PROJECT"
+ public static let hostKey = "HOST"
public static let realmKey = "REALM"
public static let refreshTokenKey = "REFRESH_TOKEN"
public static let fcmTokenKey = "FCM_TOKEN_KEY"