In a macOS app, I'm using this code to create a directory in Application Support folder.
let directoryURL = appSupportURL.appendingPathComponent("com.myCompany.myApp").appendingPathComponent("Documents")
How can the string com.myCompany.myApp obtained programmatically in Swift?
I saw this question but I'm not sure how to use it in my macOS Swift app: Access App Identifier Prefix programmatically
if let bundleIdentifier = Bundle.main.bundleIdentifier {
appSupportURL.appendingPathComponent("\(bundleIdentifier)").appendingPathComponent("Documents")
}
Little explanation: Property bundleIdentifier is optional, therefore you have to safely-unwrap the value and then you won't be asked for any exclamation mark :)
It is pretty simple to get the app ID :
let bundleIdentifier = Bundle.main.bundleIdentifier
appSupportURL.appendingPathComponent("\(bundleIdentifier)").appendingPathComponent("Documents")
A bundle identifier is the string assigned to the CFBundleIdentifier key in the bundle’s Info.plist file. This string is typically formatted using reverse-DNS notation so as to prevent name space conflicts with developers in other companies. For example, a Finder plug-in from Apple might use the string com.apple.Finder.MyGetInfoPlugin as its bundle identifier. Rather than passing a pointer to a bundle object around your code, clients that need a reference to a bundle can simply use the bundle identifier to retrieve it
For more details & other operation's details, please check
https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html
Related
I am trying to implement firebase sign in with apple but I have several issues.
Firebase provided a code for cryptographical to implement ios sign in, but I don't anything about cryptographical.
I copied all the code without any modification from:
https://firebase.google.com/docs/auth/ios/apple
And I have several issues:
authorizationController.presentationContextProvider = self
- Cannot assign value of type 'SignInOut' to type 'ASAuthorizationControllerPresentationContextProviding?'
What is this type? how do I assign it? (SignInOut - is the name of my class)
and the second issue:
let hashedData = SHA256.hash(data: inputData)
- Use of unresolved identifier 'SHA256'
What is this identifier? what should I do with it?
third, sign in with apple is available only for ios 13 and above. how can I make sure that other devices can use my app without signing in with apple?
If I implement this feature all my signing class won't be available for other versions
Am I implementing it the right way? should I just copy all the code and go on? do I need to add anything in addition? (except all my app features)
Use of unresolved identifier 'SHA256'
Firebase forgot to document that you need to import CryptoKit.
So just add import CryptoKit to the top of your file.
- Cannot assign value of type 'SignInOut' to type 'ASAuthorizationControllerPresentationContextProviding?'
I don't have an answer for this yet. But if you add your code then I can update my answer.
I'm also working on building a sample project which uses SwiftUI to implement signing in with Apple to a Firebase project. I don't know when it will be done, but maybe it will help out in the future. https://github.com/joehinkle11/Login-with-Apple-Firebase-SwiftUI
Is it possible to access SharedPreferences saved from Flutter accessed in Swift code of plugin? In Android we have FILE mode for SharedPreferences.
Any similar feature in Swift 4?
The shared_preferences uses NSUserDefaults on iOS to store the data. You can easily access it with Swift like this:
let name = NSUserDefaults.standard.string(forKey: "flutter.test")
print(name)
It would also make sense to use the optional binding to get the value safely:
if let name = NSUserDefaults.standard.string(forKey: "flutter.test") {
print(name)
}
Note, that if you use the key test in your flutter/dart code you would need to add the flutter. prefix to the key, as the shared_preferences plugin prefixes every key with it (see this line in the source code)
Use UserDefaults on Swift.
UserDefaults.standard.object(forKey:"flutter.key"))
key = key used em flutter to shared preferences.
You need to use flutter prefix on key.
I am not sure there exist anything like that, but you don't even need that.
You can fetch the value in Flutter itself, and then send the value using MethodChannel.
Has the issue of setting the bundle identifier for the GoogleAPIClientForREST/YouTube ever been resolved?
I found these but never a resolution or solution:
https://issuetracker.google.com/issues/35173446
https://github.com/google/google-api-objectivec-client-for-rest/issues/70
Seems to me if there is a pulldown to set the bundle id, there should be a way to set it in iOS, and there should be something more useful then "remove the bundle id."
I found how to do it by looking at the test source and another post here:
Test source
Hint from another stackoverflow post
let query = GTLRYouTubeQuery_SearchList.query(withPart: "id,snippet")
var bundleIdentifier = Bundle.main.bundleIdentifier
bundleIdentifier = bundleIdentifier?.trimmingCharacters(in: .whitespacesAndNewlines)
query.additionalHTTPHeaders = ["X-Ios-Bundle-Identifier" : bundleIdentifier!]
I'm using Apple's MediaLibrary framework on macOS, to write an application that reads in information on every song in my iTunes library.
I'm able to extract the artist of a song, using MLMediaObjectArtistKey as a key in the attributes dictionary (property on MLMediaObject), but how do I access the title of the song?
From what I can tell from the documentation, it seems that this information (the title) simply is not provided through the attributes dictionary.
Have others had any luck retrieving the title, and if so, how?
On a MLMediaObject:
you can use the .name attribute:
print("\(mediaObj.attributes[MLMediaObjectArtistKey]!), \(mediaObj.name!)") // Swift
Or you can use the "Name" key from a dictionary object:
mediaObj.attributes["Name"]
To get the keys from a dictionary:
print(Array(mediaObj.attributes.keys)) // Swift
Doing the final checking before submit to apple store, and noticed one thing:
bundle identifier is et to com.overwaitea.${PRODUCT_NAME:rfc1034identifier},
Is that ok? I am asking because one of the apple store guideline says "Apps with placeholder text will be rejected"... I am wondering whether this counted as placeholder, particularly that rfc part...
Should I replace all the ${PRODUCT_NAME} etc with the actual name? or the building process will actually solve for me?
Update "bundle creater os type code" is ????, what should that be?
This will replace ${PRODUCT_NAME:rfc1034identifier} with the product name as defined in the project configuration. But perhaps this is not what you want. Perhaps you created an application id in the iTunes developer portal which is not the name of the application. So you could simply replace ${PRODUCT_NAME:rfc1034identifier} by the id of your app.
But if you replace ${PRODUCT_NAME} then if later you wish to change the name of your product (which is not the identifier you chosen but the displayed name). You will have to replace anything you just replaced.