I am creating an iOS app using Xcode and Swift that uses INShortcut. After the user has created a shortcut based on a user activity using the INUIAddVoiceShortcutViewController, how would I modify the shortcut or actually the user activity in the shortcut using code without showing a user interface and update the shortcut?
Post
Replies
Boosts
Views
Activity
What is the simplest way to completely empty contents of Core Data database and start like a new database with the same data model as emptied database?
I am getting an error adding a contact to a group. I wonder if there are restrictions I am overlooking. Does the contact have to be in the container that the group belongs to? Can the contact be a member of more than one group or more than one container?How do I figure out what the error means? The documentation for CNErrorDomain doesn't give any details. Isn't there a resource that tells me what error 2 means for CNErrorDomain?Here is my code: let saveRequest = CNSaveRequest()
saveRequest.addMember(contact, from: utiGroup.cnGroup)
do {
try contactStore.execute(saveRequest)
} catch {
print("!!!!! Warning\n", error.localizedDescription)
}Here is the output in the debug window: !!!!! Warning The operation couldn’t be completed. (CNErrorDomain error 2.)
I have this code that saves records into CloudKit in iOS in an iPhone 8 Simulator, but not all records are there when I check the database after the save code succeeds in saving 688 records whether 'maxNumberOfRecordsToModify' equal 50 or 400. I am sure I did everything correctly. let privateDatabase = CKContainer.default().privateCloudDatabase
let maxNumberOfRecordsToModify = 400
func save(_ records: [CKRecord]) {
if iCloudAvailable() {
if records.count > maxNumberOfRecordsToModify {
let sliceOfRecords = Array(records[0 ..< maxNumberOfRecordsToModify])
let leftOverRecords = Array(records[maxNumberOfRecordsToModify ... records.count - 1])
let operation = CKModifyRecordsOperation(recordsToSave: sliceOfRecords, recordIDsToDelete: nil)
operation.savePolicy = CKModifyRecordsOperation.RecordSavePolicy.allKeys
operation.qualityOfService = QualityOfService.userInitiated
operation.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in
if error == nil {
print("Batch saved records!")
save(leftOverRecords)
} else {
if let err = error as? CKError, let time = err.retryAfterSeconds {
print(err)
DispatchQueue.main.asyncAfter(deadline: .now() + time) {
save(sliceOfRecords)
}
} else {
print(error!)
}
}
}
privateDatabase.add(operation)
} else {
let operation = CKModifyRecordsOperation(recordsToSave: records, recordIDsToDelete: nil)
operation.savePolicy = CKModifyRecordsOperation.RecordSavePolicy.allKeys
operation.qualityOfService = QualityOfService.userInitiated
operation.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in
if error == nil {
print("Batch saved records!")
printNumberOfRecords()
} else {
if let err = error as? CKError, let time = err.retryAfterSeconds {
print(err)
DispatchQueue.main.asyncAfter(deadline: .now() + time) {
save(records)
}
} else {
print(error!)
}
}
}
privateDatabase.add(operation)
}
}
}
func printNumberOfRecords() {
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: DatabaseNameStrings.recordTypeAffirmation, predicate: predicate)
privateDatabase.perform(query, inZoneWith: nil) {
(records: [CKRecord]?, error: Error?) in
if error != nil {
print(error as Any)
} else {
if let records = records {
print("Number of records in CloudKit=", records.count)
}
}
}
}Here is the debug window output: Batch saved records! Batch saved records! Number of records in CloudKit= 32
How do I check data in CloudKit for an actual working app on a working iOS device? I am able to log in to CloudKit Dashboard with the Apple ID, but it shows no containers even after I have installed the app on a device using that Apple ID.
When I try to sign in to iCloud in iPhone 8 Simulator, I get an error saying that the user name or passord is incorrect. I am sure it is correct. I tried it with two different accounts. I am able to use the two Apple IDs to sign in to Apple.com.
I signed out of iCloud in the iPhone 8 Simulator, and it has shown the screen saying "Removing iCloud data..." showing that it's working for a few hours now. When it did this before, I shut down the Simulator and when I opened the Simulator again, it shows that it never logged out of iCloud.
I get a code-time yellow warning message in Xcode that says:'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead... when I use the following code:let oldUbiquityIdentityToken = NSKeyedUnarchiver
.unarchiveObject(with: oldDataUbiquityIdentityToken!)When I change to unarchivedObject(ofClass:from:) I get 2 code-time red error messages before I even fill in the arguments:'NSCoding' cannot be used as a type conforming to protocol 'NSCoding' because 'NSCoding' has static requirementsStatic method 'unarchivedObject(ofClass:from:)' requires that 'NSCoding' inherit from 'NSObject'Here is the code afterwards before I fill in the parameters:let oldUbiquityIdentityToken = NSKeyedUnarchiver.unarchivedObject(ofClass: NSCoding.Protocol, from: Data)Why am I getting these error messages?
I have code to batch delete records from the private database in CloudKit, but it's not working. (I also noticed that the records I saved are not remaining.)It looks like some of the records that the code is supposed to delete is actually deleted, but some are not. When I run the code again, there exists records still, but about one less the number as before.I think the most important thing about this problem is that IT OCCURS WHEN I USE AN APPLE ID THAT IS NOT MY DEVELOPER ACCOUNT.Here is my code: class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let splitViewController = window!.rootViewController as! UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
splitViewController.delegate = self
deleteRecords()
return true
}
}
let privateDatabase = CKContainer.default().privateCloudDatabase
func deleteRecords() {
print("deleteRecords()")
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: DatabaseNameStrings.recordTypeAffirmation, predicate: predicate)
privateDatabase.perform(query, inZoneWith: nil) {
(records: [CKRecord]?, error: Error?) in
if error != nil {
print(error as Any)
} else {
if let records = records {
print("records.count=", records.count)
let recordIDsToDelete = records.map { $0.recordID }
print("recordIDsToDelete:")
print(recordIDsToDelete)
let operation = CKModifyRecordsOperation(recordsToSave: nil, recordIDsToDelete: recordIDsToDelete)
operation.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in
if error == nil {
print("Batch delete records!")
print("number of records deleted:", deletedRecordIDs?.count as Any)
printNumberOfRecords()
} else {
print(error as Any)
}
}
privateDatabase.add(operation)
}
}
}
}
func printNumberOfRecords() {
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: DatabaseNameStrings.recordTypeAffirmation, predicate: predicate)
privateDatabase.perform(query, inZoneWith: nil) {
(records: [CKRecord]?, error: Error?) in
if error != nil {
print(error as Any)
} else {
if let records = records {
print("Number of records in CloudKit=", records.count)
}
}
}
}Here is the output in the debug window from the first run of the code:deleteRecords()records.count= 93recordIDsToDelete:[<CKRecordID: 0x280bbcb00; recordName=B33A3F23-23D3-44C6-AEBC-86DD718DBB62, zoneID=_defaultZone:__defaultOwner__>, ...]Batch delete records!number of records deleted: Optional(93)Number of records in CloudKit= 67Here is the output in the debug window from the second run of the code:deleteRecords()records.count= 92recordIDsToDelete:[<CKRecordID: 0x280080d00; recordName=BBA5B236-A036-4AC9-82E1-165D3B003E23, zoneID=_defaultZone:__defaultOwner__>, ...]Batch delete records!number of records deleted: Optional(92)Number of records in CloudKit= 52
I am getting an error:One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName.I haven't even saved any data to Core Data yet.The property that has type Transformable, 'notificationIdentifiers', is of type NSObject in my NSManagedObject subclass. Why is the error saying it is unset or set to NSKeyedUnarchiveFromDataTransformerName?I also get the warning:CoreData: warning: Property 'notificationIdentifiers' on Entity 'Affirmation' is using nil or an insecure NSValueTransformer. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead.Here is my NSManagedObject subclass:extension Affirmation {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Affirmation> {
return NSFetchRequest<Affirmation>(entityName: "Affirmation")
}
@NSManaged public var body: String
@NSManaged public var count: Int64
@NSManaged public var days: NSData
@NSManaged public var frequency: Int64
@NSManaged public var notificationIdentifiers: NSObject
@NSManaged public var recordName: String?
@NSManaged public var time: NSDate
@NSManaged public var timestamp: NSDate
@NSManaged public var title: String
}When I change that property to be of type NSSecureUnarchiveFromData in my NSManagedObject subclass, I get an error saying:Use of undeclared type 'NSSecureUnarchiveFromData'I did a search on Google and I get no results telling me which library framework Use of undeclared type 'NSSecureUnarchiveFromData' belongs to.I don't think I am understanding exactly what this message is saying.Here is my entire debug window:2020-04-09 14:43:34.107774-0500 Affirmations[3922:921109] [error] fault: One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using "NSSecureUnarchiveFromData" when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.CoreData: fault: One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using "NSSecureUnarchiveFromData" when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.2020-04-09 14:43:34.108286-0500 Affirmations[3922:921109] [error] CoreData: One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using "NSSecureUnarchiveFromData" when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.CoreData: warning: Property 'notificationIdentifiers' on Entity 'Affirmation' is using nil or an insecure NSValueTransformer. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead.
I have the latest Xcode and the latest iOS on my iPhone 8.Why am I getting this message when I run my project on my iPhone 8?Could not locate device support files.This iPhone 8 (Model ...) is running iOS 13.4 (...), which may not be supported by this version of Xcode. An updated version of Xcode may be found on the App Store or at developer.apple.com.
Is there a way to use code in iOS using Swift to access a text message and read the contacts and addresses in that message?
How do I show storyboard in Xcode 11 like it showed in Xcode 10, instead of an xml file?
How would I take the tint off of a bar button item so that the image of the button shows as is? With the tint set, blue being the default, it shows the image as that color instead of the actual image.
If I remove app in App Store Connect, can I add the app back at any time without any trouble?