I have been playing around with CloudKit and I was under the impression that the user needed to be logged-in into iCloud in order to use CloudKit, but I don't think it's true.
I'm testing an app that successfully communicates with the private database in CloudKit, I can read and write records to it. To my surprise I logged-off from my iCloud account and from the Sandbox Account and I can still read and write records from CloudKit which was unexpected, I was thinking that after logging off I wouldn't be able to communicate with CloudKit, in fact, I deleted the app from my phone, recompiled in Xcode and the app can still communicate with CloudKit.
Is this normal behavior, does CloudKit works without the user being logged into iCloud?
Thanks
I have an app where I can create and share records with other users. When I share a record and the user accepts it, I can display the shared object right after the `userDidAcceptCloudKitShareWith` gets called and using the `CKFetchRecordsOperation` class to fetch the object, no issues here. My problem is trying to read the shared records directly from the `Shared Database` after the user has accepted the record, closed the app, and reopened the app again.The following code successfully reads all of the records from the `Private Database` located in a zone called `ListsZone`. @IBAction func sharedRecords(_ sender: Any) {
let privateDatabase = CKContainer.init(identifier: "iCloud.com.mySite.lists").database(with: .private)
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Items", predicate: predicate)
let ckRecordZoneID = CKRecordZone(zoneName: "ListsZone")
let ckRecordID = CKRecord.ID(zoneID: ckRecordZoneID.zoneID)
privateDatabase.perform(query, inZoneWith:ckRecordID.zoneID){( results , error) in
guard error == nil else{
print("Error \(String(describing: error?.localizedDescription))")
return
}
if let itemsFromResults = results{
print("Items: \(itemsFromResults)")
}
}
}What I'm expecting is to be able to read the shared records from the `Shared Database` with the same code above except modifying the line below, but it's not working.let privateDatabase = CKContainer.init(identifier: "iCloud.com.mySite.lists").database(with: .shared)I get the following error."Only shared zones can be accessed in the shared DB"What am I missing?What is the proper way to read records from the `Shared Database`?I was under the impression that users who already accepted a shared record from a user and the records are saved in the `Shared Database` the user could access the records by requiring the `Shared Database` directly as shown in my code above.FYI - I know there are shared records in the shared database because I can see them in the CloudKit dashboard.
Post not yet marked as solved
I'm trying to share a record with other users in CloudKit but I keep getting an error. When I tap one of the items/records on the table I'm presented with the UICloudSharingController and I can see the iMessage app icon, but when I tap on it I get an error and the UICloudSharingController disappears, the funny thing is that even after the error I can still continue using the app.Here is what I have.Code var items = [CKRecord]()
var itemName: String?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let item = items[indexPath.row]
let share = CKShare(rootRecord: item)
if let itemName = item.object(forKey: "name") as? String {
self.itemName = item.object(forKey: "name") as? String
share[CKShareTitleKey] = "Sharing \(itemName)" as CKRecordValue?
} else {
share[CKShareTitleKey] = "" as CKRecordValue?
self.itemName = "item"
}
share[CKShareTypeKey] = "bundle.Identifier.Here" as CKRecordValue
prepareToShare(share: share, record: item)
}
private func prepareToShare(share: CKShare, record: CKRecord){
let sharingViewController = UICloudSharingController(preparationHandler: {(UICloudSharingController, handler: @escaping (CKShare?, CKContainer?, Error?) -> Void) in
let modRecordsList = CKModifyRecordsOperation(recordsToSave: [record, share], recordIDsToDelete: nil)
modRecordsList.modifyRecordsCompletionBlock = {
(record, recordID, error) in
handler(share, CKContainer.default(), error)
}
CKContainer.default().privateCloudDatabase.add(modRecordsList)
})
sharingViewController.delegate = self
sharingViewController.availablePermissions = [.allowPrivate]
self.navigationController?.present(sharingViewController, animated:true, completion:nil)
}
// Delegate Methods:
func cloudSharingControllerDidSaveShare(_ csc: UICloudSharingController) {
print("saved successfully")
}
func cloudSharingController(_ csc: UICloudSharingController, failedToSaveShareWithError error: Error) {
print("failed to save: \(error.localizedDescription)")
}
func itemThumbnailData(for csc: UICloudSharingController) -> Data? {
return nil //You can set a hero image in your share sheet. Nil uses the default.
}
func itemTitle(for csc: UICloudSharingController) -> String? {
return self.itemName
}ERRORFailed to modify some records Here is what I see...https://i.stack.imgur.com/0SLlK.pngAny idea what could be wrong?
Post not yet marked as solved
With the following code, I can successfully create a reminder event and add an alarm to it that triggers 10 seconds after the event has been created. What I don't like about the way the reminder is created is that it shows in the Apple's Reminders app and when you get the notification message in your device, it shows the Reminders' app icon.Is it possible to make the reminder private so it doesn't show in Apple's Reminders app? If not, what are my options to achieve such of task?import EventKit
class ViewController: UIViewController{
var eventStore = EKEventStore()
override func viewDidLoad(){
super.viewDidLoad()
// get user permission
eventStore.requestAccess(to: EKEntityType.reminder, completion: {(granted, error) in
if !granted{
print("Access denied!")
}
})
}
@IBAction func createReminder(_ sender: Any) {
let reminder = EKReminder(eventStore: self.eventStore)
reminder.title = "Get Milk from the Store"
reminder.calendar = eventStore.defaultCalendarForNewReminders()
let date = Date()
let alarm = EK Alarm(absoluteDate: date.addingTimeInterval(10) as Date)
reminder.addAlarm(alarm)
do {
try eventStore.save(reminder, commit: true)
} catch let error {
print("Error: \(error.localizedDescription)")
}
}
}FYI - To make the above code work you would need to add the NSRemindersUsageDescription key in the info.plist file.RemindersUsageDescription key in the info.plist file.Also, please note the space in class `EK Alarm`, for some reason it would let me add it as one word I had to add a space.
Hi,Can someone please summaries and explain the logic/process for creating a reminders app?I'm no looking for code I just need the list of frameworks and steps needed for creating a reminders app1. You fist create a calendar event (what framework/methods?).2. Than you load the calendar event (what framework/methods?).3. Than you notify the user (what framework/methods?).I know this is a very broad question but I have to start some where.Thanks
Hi,I'm currently setting up an Auto Renewable subscription and I was wondering if there is a way to limit the services offered in this subscription to only the US since they are only relevant to user in the US.Is there a way to limit the services offered in an Auto Renewable subscriptions to only the US?Thanks
I recently submitted an app for review that contains auto-renewing subscriptions and it got rejected because the app did not fully meet the terms and conditions for auto-renewing subscriptions.Rejection Message:We noticed that your app did not fully meet the terms and conditions for auto-renewing subscriptions, as specified in Schedule 2, section 3.8(b) of the Paid Applications agreement.I'm having a hard time making these documents since most of the ones I have seen are really long and I'm not sure what specifically do I need in those documents for my app.1. How detailed does the terms and conditions files for auto-renewing subscriptions need to be? Can it be really simple?2. Do I need two separate documents, a Privacy Policy and Terms of Use file?3. How is there a template that I could use as a start?Any information about the topic will greatly appreciate it.Thanks.
Hi,I have an app that offers auto-renewable subscriptions and I would like to increase the subscription cost but I'm not sure how to handle existing customers. Let's pretend for a moment that I currently have 100 subscribers who paid $9.99/year when they first subscribed, what would happen if I increase the subscription cost to let say, $19.99/year in the middle of their payment cycle, are they going to be notified before the next renewal date and give them the chance to cancel or it will just auto-renew automatically without letting the user know about the cost increase?Thanks!
Post not yet marked as solved
Hi,I'm currently using XCode 10.1 and Mojave 10.14.2 and it's driving me crazy, it slows my computer down to a point that it is unusable. Before I upgraded to XCode 10 I was running the same project on XCode 9 and High Sierra without any problems and with only half of the memory it currenly has (8GB of Ram). I now have upgraded the memory to 16GB and but it didn't make a difference.FYI - I don't think the slow down has to do with Mojave 10.14.2 since I was experiencing the same issue with High Sierra and XCode 10, which is the reason I upgraded to Mojave thinking that XCode 10 would run smoother in the newest operating system.Here are the specs of my compter:1TB fusion drive.https://www.dropbox.com/s/arhltblqs6vurhk/Computer%20Specs.png?dl=0Here is what I see in Activity Monitor:https://www.dropbox.com/s/k6l9eljkl8ichjw/memory.png?dl=0https://www.dropbox.com/s/p56ge9neig1ww1g/CPU.png?dl=0Any idea what could be wrong?Thanks
Post not yet marked as solved
I need to get the zipCode and city from multiple locations in my app so I created the following class.import Foundation
import CoreLocation
class MyLocationManager: NSObject, CLLocationManagerDelegate {
private let locationManager = CLLocationManager()
private var zipCode:String?
private var city:String?
static let shared = MyLocationManager()
private override init() {
super.init()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLLocationAccuracyHundredMeters
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error)-> Void in
if error != nil {
//AlertView to show the ERROR message
}
if placemarks!.count > 0 {
let placemark = placemarks![0]
self.locationManager.stopUpdatingLocation()
self.zipCode = placemark.postalCode ?? ""
self.city = placemark.locality ?? ""
}else{
print("No placemarks found.")
}
})
}
public func getZipCode()->String {
return zipCode ?? ""
}
public func getCity()->String {
return city ?? ""
}
}The issue is that the first time I call the getZipCode() or the getCity() methods I get an empty string. Here is how I'm using it in a viewController...class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("Location: \(MyLocationManager.shared.getCity())")// empty
}
/// Action to test it after viewDidLoad with a button
@IBAction func testing(_ sender: Any) {
print("Location: \(MyLocationManager.shared.getCity())")// returns the name of the city
}
}In viewDidLoad I get an empty string but when I tap the testing button (second call) I do get the name of the city.How can I make it update the city name in viewDidLoad as soon as I call MyLocationManager.shared.getCity()?
Post not yet marked as solved
Hi,I need some advice, I have a big CSV file (about 3MB, 50,000 entries) that I will be using in my app to retrieve some information but I'm not sure what would be the best way to do it. What I need to do is be able to search the CSV file using Swift.1. What is the most common method to handle CSV files in Swift/iOS?2. Is it possible to add the file directly to XCode and make searches with Swift? 3. Is 3MB considered too big of a file to be directly in the app?Any advice will be greatly appreciated. Thanks.
Post not yet marked as solved
Hi,I created an Apple Watch application which is working fine but now I would like to be able to launch it from a complication. All I want is to show an image in one of the complications so the user can launch it faster. But no matter what I do I can not make the images to display in the complications, they just show as solid-white rectanglesThis is what I did...1. I created four different image sizes in Sketch App, a 32x32.png, a 40x40.png, a 52x52.png and a 182x182.png.2. Added them in the complications assets, Circular, Extra Large, Modular and Utilitarian.3. Compiled but all I see is blank-white rectangular images.Is there a special process to add images for complications? Do I need to do that in code? Any suggestion?Again, all I want is to display the logo of my Apple Watch App in one of the complications for launching purposes.Thanks a lot!