Skip to content

Using already existing nstack plist to obtain appid and apikey #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
if !Style.registerFonts() {
fatalError()
}
localizations = startNStackSDK(
appId: <#appID#>,
restAPIKey: <#restAPIKey#>
)

var localizations: ObservableLocalizations = {
guard
let url = Bundle.main.url(forResource: "NStack", withExtension: "plist"),
let config = try? PropertyListDecoder().decode(NStackConfig.self, from: try Data(contentsOf: url))
else {
fatalError("Failed to initialize NStack")
}
return startNStackSDK(appId: config.appId, restAPIKey: config.apiKey)
}()
Comment on lines +45 to +53
Copy link

@jakobmygind jakobmygind Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think the callsite should be as it was where NStack is started just with the ids, but there could be a convenience function that would get the keys from the plist the lines before, I think this might be nice 😊 This seems a little more messy than is necessary in this particular location which we would like to be very clear, since it's the entrypoint for everything imo


let baseURL = Configuration.API.baseURL

Expand Down
12 changes: 11 additions & 1 deletion Modules/Sources/Localizations/NStackAccessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ internal func loadTranslationsFromJSON(_ filename: String, in bundle: Bundle) ->

let data = try! String(contentsOfFile: path).data(using: .utf8)!
let dict =
try! JSONSerialization.jsonObject(with: data, options: .allowFragments) as! [String: Any]
try! JSONSerialization.jsonObject(with: data, options: .allowFragments) as! [String: Any]
let translationsData = try! JSONSerialization.data(
withJSONObject: dict["data"]!, options: .fragmentsAllowed)

let result = try! JSONDecoder().decode(Localizations.self, from: translationsData)
return result
}

public struct NStackConfig: Decodable {
public let appId: String
public let apiKey: String

enum CodingKeys: String, CodingKey {
case appId = "APPLICATION_ID"
case apiKey = "REST_API_KEY"
}
}
4 changes: 4 additions & 0 deletions PROJECT_NAME.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
A8BC8D602816BD050038936E /* NStack.plist in Resources */ = {isa = PBXBuildFile; fileRef = A8BC8D5F2816BD040038936E /* NStack.plist */; };
BD1B2304274679C100F9B140 /* Localizations in Frameworks */ = {isa = PBXBuildFile; productRef = BD1B2303274679C100F9B140 /* Localizations */; };
BD2B080727833D070066D559 /* AppFeature in Frameworks */ = {isa = PBXBuildFile; productRef = BD2B080627833D070066D559 /* AppFeature */; };
BD2FEFDB2768CA5C00E80BBC /* APIClientLive in Frameworks */ = {isa = PBXBuildFile; productRef = BD2FEFDA2768CA5C00E80BBC /* APIClientLive */; };
Expand All @@ -31,6 +32,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
A8BC8D5F2816BD040038936E /* NStack.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = NStack.plist; sourceTree = SOURCE_ROOT; };
BD3196E92796CB440077C271 /* Production.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Production.xcconfig; sourceTree = "<group>"; };
BD3196EA2796CB690077C271 /* Test.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Test.xcconfig; sourceTree = "<group>"; };
BD3196EB2796CC900077C271 /* ProjectConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectConfig.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -91,6 +93,7 @@
BDCA8DAE2742611D00195B05 /* Info.plist */,
BD3196E92796CB440077C271 /* Production.xcconfig */,
BD3196EA2796CB690077C271 /* Test.xcconfig */,
A8BC8D5F2816BD040038936E /* NStack.plist */,
BD3196EB2796CC900077C271 /* ProjectConfig.swift */,
);
path = App;
Expand Down Expand Up @@ -165,6 +168,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A8BC8D602816BD050038936E /* NStack.plist in Resources */,
BDCA8DAD2742611D00195B05 /* LaunchScreen.storyboard in Resources */,
BDCA8DAA2742611D00195B05 /* Assets.xcassets in Resources */,
);
Expand Down