requestApplicationPermission userDiscoverability failed in Mac Catalyst - cloudkit

I have ios app using requestApplicationPermission userDiscoverability. Today, I add Mac Catalyst support, but failed: "requestApplicationPermission(.userDiscoverability) failed, error: CloudKit access was denied by user settings".
container.requestApplicationPermission(.userDiscoverability) { [weak self] (status, error) in
guard let self = self else { return }
DispatchQueue.main.async {
if let error = error {
foolPrint("requestApplicationPermission(.userDiscoverability) failed, error: \(error.localizedDescription)")
}
}
}
And I cannot find settings about userDiscoverability in mac settings, where is it?

This iCloud user guide shows how to change these settings:
On iCloud.com, go to Account Settings, then click Manage Apps That Can Look You Up in the Advanced section.
To prevent an app from showing your name and email address to other users, deselect the app’s checkbox in the list.

Related

CNContactStore execute fails

I am working out how to use the Contacts framework, however some fairly simple code to create a contact is failing with an unexpected result. This is my code:
let Store = CNContactStore()
Store.requestAccess(for: .contacts, completionHandler:{ success, error in
if success {
let Contact = CNMutableContact()
Contact.givenName = "Dave"
Contact.familyName = "Nottage"
let SaveRequest = CNSaveRequest()
SaveRequest.add(Contact, toContainerWithIdentifier: nil)
do {
try Store.execute(SaveRequest)
print("Success")
}
catch let error as NSError {
print(error.localizedDescription)
}
} else {
print("No access")
}
})
..and this is the result:
2019-02-22 10:30:56.050344+1030 ContactsTest[30329:25254955] [default] Unable to load Info.plist exceptions (eGPUOverrides)
2019-02-22 10:30:57.973724+1030 ContactsTest[30329:25254955] Could not get real path for Address Book lock folder: open() for F_GETPATH failed.
2019-02-22 10:30:57.973954+1030 ContactsTest[30329:25254955] Unable to open file lock: <ABProcessSharedLock: 0x600001752ac0: name=(null), lockFilePath=(null), localLock=<NSRecursiveLock: 0x600002914a80>{recursion count = 0, name = nil}, fileDescriptor=-1> Error Domain=NSPOSIXErrorDomain Code=14 "Bad address" UserInfo={ABFileDescriptor=-1}
The operation couldn’t be completed. (Foundation._GenericObjCError error 0.)
Any ideas on what might be causing this?
Edit: Note also that this is being compiled for macOS 10.14 SDK, and is running on macOS 10.14.3
The answer is to check the Contacts checkbox of App Data in the App Sandbox section in Capabilities and turn on the switch for App Sandbox.
Make sure you added key NSContactsUsageDescription in Info.plist.
Please refer to link.
Important
An iOS app linked on or after iOS 10.0 must include in its Info.plist
file the usage description keys for the types of data it needs to
access or it will crash. To access Contacts data specifically, it must
include NSContactsUsageDescription.

iTunesLibrary get all music

I'm new on swift 4.
I'm trying to develop a simple mac program to get all music songs from iTunesLibrary. I did sign my code and import iTunesLibrary.framework to the project. But I get an error about iTlib XPC connection error:
2018-05-29 19:51:16.277312+0700 KODE[2325:47137] ITLib received
XPC_ERROR_CONNECTION_INTERRUPTED connection error (can be ignored).
2018-05-29 19:51:16.277410+0700 KODE[2325:47137] ITLib xpc error:
Connection interrupted
2018-05-29 19:51:16.277441+0700 KODE[2325:47072] Assertion failure:
status == noErr (100005)
Here is my code
override func viewDidLoad() {
super.viewDidLoad()
let library: ITLibrary
do {
library = try ITLibrary(apiVersion: "1.0")
} catch {
print("Error occured!")
return
}
let tracks = library.allMediaItems
for track in tracks {
print(track.album.title!)
}
// Do any additional setup after loading the view.
}
If you have a sandboxed app, go to Capabilites/"App Sandbox"/"File Access"/"Music Folder". Change "None" to "Read Only". It helped me. Also app must be properly signed.

CloudKit - "Invalid bundle ID for container"

I've just create a project in Xcode 9 beta 6 and add this code:
let privateDB = CKContainer.default().privateCloudDatabase
let greatID = CKRecordID(recordName: "GreatPlace")
let place = CKRecord(recordType: "Place", recordID: greatID)
privateDB.save(place) { (record, error) in
if error != nil {
let er = (error as! CKError).errorUserInfo
print("Error: \n")
print("CKErrorDescription: \(er["CKErrorDescription"]!)\n")
print("ContainerID: \(er["ContainerID"]!)\n")
print("NSDebugDescription: \(er["NSDebugDescription"]!)\n")
print("NSUnderlyingError: \(er["NSUnderlyingError"]!)\n")
print("NSLocalizedDescription: \(er["NSLocalizedDescription"]!)\n")
print("ServerErrorDescription: \(er["ServerErrorDescription"]!)\n")
}
if record != nil {
print("record: \(record!)")
}
}
and add this capabilities:
and when I run the code I receive this error message:
What I am doing wrong ?
There was a bug causing some associations to be missed. That bug has been fixed and we automatically fixed the container/app associations that were broken during that time.
If for some reason you still need to redo an association you can either use the Capabilities pane in Xcode or use developer.apple.com -> Certificates, Identifiers & Profiles -> App IDs -> pick the ID -> Edit -> Edit under iCloud -> check the box for the container to disassociate, save, then re-associate.
If you're still stuck please email cloudkit[at]apple.com
My friend and I are having the same issue. We made 2 different projects and both of them had the same error message "Invalid bundle ID for container" which is CKError case 10 .
We are calling our fetch function to get the default "Users" record in the viewDidLoad.
func fetchWorkoutCompleted(completion: #escaping (Error?) -> Void = { _ in }) {
cloudKitManager.fetchRecord(ofType: "Users", sortDescriptors: nil) { (records, error) in
if let error = error {
print(error.localizedDescription)
completion(error)
return
}
guard let records = records else { completion(nil); return }
completion(nil)
}
}
Using Xamarin.IOS, I had to select manual provisioning rather than automatic provisioning in the info.plist file.
Had the same issue. what worked for me was changing the iCloud group name.
Before it was something like this: iCloud.com.companyName.appName.randomString
After changing to: iCloud.com.companyName.randomString it started working and synchronising.
If after adding the new container it's red press the refresh button(from under the groups) and try a clean install on your phone and it should work
Thanks to Dave Browning, this is based on his answer.
Following worked for me:
Check the container id
Check the container id used for initialisation of CKContainer
Note: If you are using NSPersistentCloudKitContainer we wouldn't be using the container id directly would be picked automatically from the entitlements file.
Try to disable and enable iCloud on the App ID
Disable and Enable iCloud on App ID
Go to https://developer.apple.com and sign in
Select Certificates, Identifiers & Profiles
Select Identifiers (App IDs)
Edit App ID for the app
Uncheck iCloud
Save
Check iCloud
Quit Xcode and Clear DerivedData
Run app

Problems accessing Calendar using EKEventStore on OSX Sierra with Swift 3

This appears very simple, but I've been struggling for several days to get access to the Calendar on OSX. I have switched on the App Sandbox capability, and I've ticked the "Calendar" box in App Data. I have created very simple app with the following view controller class:
import Cocoa
import EventKit
class ViewController: NSViewController {
var eventControl = EKEventStore()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
As you can see, the only lines of code I've added are to import EventKit and to initialise eventControl.
When I run this in debug, I get an error at the eventControl initialisation line
2016-10-28 15:02:00.056521 calendarTest[4105:847101] CoreData: XPC: Unable to load metadata: Error Domain=NSCocoaErrorDomain Code=134070 "An error occurred in the persistent store." UserInfo={Problem=request failed, insufficient permission}
2016-10-28 15:02:00.057742 calendarTest[4105:847101] [error] error: -addPersistentStoreWithType:NSXPCStore configuration:(null) URL:file:///Users/patrickramsden/Library/Calendars/Calendar%20Cache options:{
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
agentOrDaemon = 1;
serviceName = "com.apple.CalendarAgent.database";
} ... returned error Error Domain=NSCocoaErrorDomain Code=134070 "An error occurred in the persistent store." UserInfo={Problem=request failed, insufficient permission} with userInfo dictionary {
Problem = "request failed, insufficient permission";
}
I can't work out how to get the right permissions.
I am using Xcode 8.1 and macOS Sierra 10.12.1
You need to add a usage description to your info.plist. This is a small description of why you need access to the services that is presented to the user.
<key>NSCalendarsUsageDescription</key>
<string>Description of why you need access to the Calendar</string>
Has anyone else figured this out?
I am running into the same issue, however trying to access anything in the event Store returns nil. Even though "access is granted". Such as:
let eventStore = EKEventStore()
switch EKEventStore.authorizationStatus(for: .event) {
case .authorized:
print("Access Granted")
break
case .denied:
print("Access denied")
case .notDetermined:
eventStore.requestAccess(to: .event, completion:
{(granted: Bool, error: Error?) -> Void in
if granted {
print("Access Granted")
} else {
print("Access denied")
}
})
break
default:
print("Case Default")
break
}
print(eventStore.calendars(for: .event))
Getting the same messages: How to prevent EventStore access error on first run
However the access is working correctly once you start the application again after the user grants permission! My app is not sandboxed. Have you set the "Privacy - Calendars Usage Description" key in your plist?

Facebook Login Error - Xcode 8 GM

I am using the latest Facebook SDK and I get this error when I run the block of code below: Facebook signup error - The operation couldn’t be completed. (com.facebook.sdk.login error 308.)
Here is my code:
func signupWithFacebook() {
FBSDKLoginManager().logIn(withReadPermissions: ["public_profile"], from: self) { (result, error) in
if let error = error {
print("Facebook signup error - \(error.localizedDescription)")
} else if result != nil {
let credential = FIRFacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
self.facebookSignup = true
self.addUserToAuth(credential, twitterUserID: "")
}
}
}
I Figured it out! It has to do with the way Apple deals with Keychain. All you have to do is go into the "Compatibilities" tab under the target for your app and turn "Keychain Sharing" on. Here is a more fulfilling answer.