iOS 11 MDM: managed app configuration doesn't work - swift

let serverConfig = UserDefaults.standard.dictionary(forKey: "com.apple.configuration.managed") print("serverConfig count:
\(String(describing: serverConfig?.count))")
Above code always returning nil for iOS 11.
I want transfer few data to managed application using MDM portal via managed configuration as per the apple developer document they didn't update anything in to it.
I don't know what I'm doing wrong.Please help me out with this.

Related

How can an iOS app written in Swift be notified when USB flash drives connect or disconnect?

I'm working on an iOS app written in Swift and I want to be able to detect when USB flash drives are connected or disconnected from the device. How can I do this in my app?
I've looked into using the External Accessory framework, but I'm not sure how to get started. Can anyone provide some guidance or point me to some resources that can help me implement this feature in my app?
Any help would be greatly appreciated!
let keys: [URLResourceKey] = [
.volumeNameKey, .volumeIsRemovableKey,
.volumeIsEjectableKey, .volumeAvailableCapacityKey,
.volumeTotalCapacityKey, .volumeUUIDStringKey,
.volumeIsBrowsableKey, .volumeIsLocalKey, .isVolumeKey
]
let manager =
FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: keys)
if let urls = manager {
print(urls)
}
This code for example works on MacOS , I get a list of volumes.
However, in iOS it just returns nil.

Back4app with Stripe using swift iOS

I'm trying to build an iOS app with back4app acting as the db. I've added Stripe to the cloud code and I've added all the relevant API keys to it.
I've been following https://www.back4app.com/docs/cloud-code-functions/stripe-android-app as documentation.
Being an Android app, I'm not sure which cloud code functions I should use when trying to test a payment using Swift.
Hope someone can help. Thanks.
Back4App utilises the open source Parse Server and the wider Parse Platform including our open source client SDKs for iOS, Android, JavaScript, Flutter, PHP and more.
With this in mind much of our open source documentation is relevant to using Back4App. The extensive guides should help get you up to speed and answer most simple questions.
Following on from #Paul's suggestion, to call a cloud function using the iOS SDK you can do something like this...
PFCloud.callFunction(inBackground: "purchaseItem", withParameters: nil) { (result, error) in
guard error == nil else {
return
}
guard let result = result as? String else {
return
}
print("Wow \(result).")
}

iCloud syncing of Core Data with Ensembles

My plan is to purchase Ensembles 2 (to take advantage of speed/efficiencies etc) but am trying to make sure that I will be able to get it to work (in a test Swift project) first. To do this I am experimenting with v1.
Using the Simple Sync with Swift as a guide I have incorporated ensembles into my xcode project.
The data from the app does appear to be getting stored in iCloud as when I delete the app and then re-add it, leeching and then syncing does restore the correct data from iCloud. My trouble is that testing with a second device (signed in to the same apple/iCloud account) does the same thing with its own data. The data from the 2 devices is never merged. However the data created on each device is restored to its own device after reloading the app.
Does anyone know how this could be?
Am wondering if the problem might be the store url that I am generating. A lot of the Core Data Stack set up is now done automatically in Swift 3+ (NSPersistentContainer) and so these things do not need to be generated by the user. Here is how i am generating the variables for store url and model url to use when setting up my ensemble:
var storeDirectoryURL: URL {
return try! FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
}
var storeURL: URL {
return storeDirectoryURL.appendingPathComponent("VsSyncTest.sqlite")
}
// Setup Ensemble
let modelURL = Bundle.main.url(forResource: "VsSyncTest", withExtension: "momd")
The only way I can imagine that would happen is if either you are using different iCloud accounts, or you have a different ensemble identifier for each device.
Note also that the iCloud document sharing can be stubborn. Just because the files get added to the container locally does not mean they will immediately transfer to the other device. (CloudKit backend is much better in that respect, but only in E2.)
If you are testing with the simulator, using Debug > iCloud > Trigger Sync in Simulator may help.

Watchkit Extension Cannot Read from iCloud

I am looking for the watchkit extension to read a file from iCloud document storage. I wrote the file from the iOS app which is also able to read it. I am leveraging a shared class so the code is the same. The problem is that on the watch, the URL for the cloud container returns nil.
static func readFromFile(fileName:String) -> String?
{
let fileManager = FileManager.default
var cloudURL = fileManager.url(forUbiquityContainerIdentifier: nil)
cloudURL = cloudURL?.appendingPathComponent("Documents/\(fileName)")
do
{
return try String(contentsOf: cloudURL!)
} catch {
print (error)
return nil
}
In the case above, cloudURL is nil on the watch but not the phone. For the forUbiquityContainerIdentifier I checked that the same identifier is used for both watch and phone. I have also tried to directly enter the name rather than using nil and letting it grab it from the entitlements. The format of the container:
iCloud.com.company.app
It's my understanding that Watch OS 3 is supposed to be able to use iCloud.
Update:
I printed out let token = fileManager.ubiquityIdentityToken and I get the following:
WatchKit Extension[390:687462] [default] [ERROR] error while getting
ubiquityIdentityToken: Error Domain=NSCocoaErrorDomain Code=4099 "The
connection to service named com.apple.bird.token was invalidated."
UserInfo={NSDebugDescription=The connection to service named
com.apple.bird.token was invalidated.}
I have officially heard back from Apple that this is not a supported feature of Watch OS. This runs contrary to their own documentation which I let them know about. Hopefully others see this response and it can save a ton of time that I wound up wasting.
It was 2021. Apple documentation still says that iCloud Drive methods can be used by watchOS 2.0+, but url forUbiquityContainerIdentifier returns nil :(

Swift UserDefault :sharing data via share group doesn't work

just started swifting recently and got an issue by using app group to share data between iOS devices.
basically I have setup the project followed the steps below:
[iPhone]
Enabled App Group for the iPhone target
initialed data below(groupID is matched what I set in the project):
sharedDefaults = NSUserDefaults.init(suiteName: groupID)
sharedDefaults?.setObject("User Default Shared String", forKey: "test")
sharedDefaults?.synchronize()
double checked the test string by loading user default locally, which is able to display in the Log.
let t_sharedDefaults = NSUserDefaults.init(suiteName: groupID);
t_sharedDefaults?.synchronize();
let str = t_sharedDefaults?.valueForKey("test") as! String;
print(str);
[watch extension]
Create a new watch extension target.
Enable App Group.
Load the User default data under awake with context via the code below:
sharedDefaults = NSUserDefaults.init(suiteName: groupID);
sharedDefaults?.synchronize();
let str = sharedDefaults?.valueForKey("test")
print(str);
I have run the iPhone target first, and then the watch app.
However, the watch app is not able to read expected data from the user default.
I have also uploaded the test project in Github, please let me know if you have any thought on this issue.
[Github]
https://github.com/mattcn/WatchOS_DataSharing
Thanks for your help in advance.
In Watch OS1 this worked, but in Watch OS2 there has been some changes. You need to use something called WatchConnectivity to send the data you want to save to the watch.
so even if you use shared user defaults or app groups the data you put inside them will be on the watch and so not accessible from the iOS app.
To send data to the watch you can use the WatchConnectivity framework.
Thanks Ashish to bring the difference between OS1 and OS2 up.
just found a good reference from:
NSUserDefaults(suiteName:) on iOS 9 and WatchOS 2 - not working?
In watchOS 2 you need to keep in mind that there is 2 different processes running:
Apple Watch Process
iPhone Process
Both of these processes have their own sandbox that's why they call it "native", so if you try to use the shared NSUserDefaults it will not work because the Apple watch app has a completely different sandbox than the host iPhone app.
If you want to save something from your phone to the NSUserDefaults on the Apple watch Target:
Use WatchConnectivity to send the data you want to save to the watch. Then when the watch receives the data you sent to it, save it to the Apple watch's default NSUserDefaults.