Cloudkit: " error saving record WRITE operation not permitted" - cocoa

I'm trying to save a record CloudKit but I'm getting the following error from cloudkit:
error saving record este es error: Error saving record <CKRecordID: 0x7fef15b5d2a0; 2:(_defaultZone:__defaultOwner__)> to server: WRITE operation not permitted
Here is how I'm trying to save the record:
[publicDatabase saveRecord:recordContent completionHandler:^(CKRecord *record, NSError *error){
if (!error)
{
NSLog(#"saved!!!");
}
else
{
if ([[error.userInfo valueForKey:#"ErrorDescription"] isEqualToString:#"record to insert already exists"])
{
NSLog(#"record already exist %#",[error.userInfo valueForKey:#"ErrorDescription"]);
}
NSLog(#"error saving record : %#",error.localizedDescription);
}
}];
But before had I check if cloudkit is available:
[myContainer accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error)
{
NSLog(#" no error but status %ld",accountStatus);
if (((accountStatus == 3) || (accountStatus == 2)) && (!error))
{
NSLog(#" no error but status %ld",accountStatus);
// typedef NS_ENUM(NSInteger, CKAccountStatus) {
// /* An error occurred when getting the account status, consult the corresponding NSError */
// CKAccountStatusCouldNotDetermine = 0,
// /* The iCloud account credentials are available for this application */
// CKAccountStatusAvailable = 1,
// /* Parental Controls / Device Management has denied access to iCloud account credentials */
// CKAccountStatusRestricted = 2,
// /* No iCloud account is logged in on this device */
// CKAccountStatusNoAccount = 3,
//
// }
}
if (error)
{
NSLog(#" accountStatus error %#",error);
}
} ];
Where I'm getting status 1, meaning CKAccountStatusAvailable.
Any of you knows why this is happening it has been working fine until the last record or any of you knows a work around this?
I'll really appreciate your help.

You need to set permission to allow a user to write (or delete) a record created by someone else. You do that in the Development Environment, under Schema, Record Types, select the specific record, then over on the right there is a drop down menu labelled Security. Grant to the Role ' Authenticated' the right to Read and Write. Then deploy to Production.

This was moved in the latest CloudKit, took me a while to track it down.
Beware, this isn't instant, it takes a while for these changes to propagate after saving them. Come back later and refresh the page to see if they've been applied.
If you are still getting this error after setting these permissions and letting them propagate then it's likely that your iCloud Login in Simulator is messed up. Logging out of iCloud and logging in again fixed this for me.

I spent 2 days for "Permission failure (10/2007)". All permissions and security roles was set as in William.T picture. Relogin into iCloud doesn't got any results.
The snag was in one small setting (not documented by Apple) - it was switcher "iCloud Drive" which located in
Settings/[your account]/iCloud/iCloud Drive
on my device. Apple's documentation is terrible! no one will return me 2 days spent.
Hope this helps someone with the same problem.

In my case i forgot to do a basic check: make sure you're logged in with your Apple ID and make sure the iCloud checkmark for your application is turned on.
This can happen especially using Simulators.

Related

Facebook SDK inside iOS app extension cannot find logged in user?

I've created a sample app Share extension. Followed the Apple guides, which means my project consists of a main app and a "share extension" target.
I've setup my Facebook SDK inside the main app, since the app's settings has some FB login/status functionality. It works well according to expectation: users can login and do some shares.
But I also want the logged-in user to be available to the extension target itself. When my extension comes up (in any app), I check Facebook's login status in viewDidLoad:, and it outputs "not logged in":
if ([FBSDKAccessToken currentAccessToken]) {
NSLog(#"logged in");
} else {
NSLog(#"not logged in");
}
The same code outputs "logged in" if called from within the main app. I suspect it has something to do with the fact that the extension target has a different bundle ID that looks like this: .suffix and I guess FB SDK is trying to read the user ID off the keychain cache, but maybe it's reading it off the wrong keychain due to the different bundle IDs... But it could be other reasons as well I guess.
Any idea how to keep Facebook SDK "logged in" inside the extension after the login itself occurred in the containing main app?
I have the exact same problem, as I develop a Message Extension App with a Facebook Login.
To solve the problem, I put the Login Button in the App and use the shared UserDefaults (with a group name) to store a property :
/*
* Get / sets if is FB connected (because we can't use FB SDK in Extension)
*/
public var isFacebookConnected : Bool {
get {
// Getting Bool from Shared UserDefaults
let defaults : NSUserDefaults = NSUserDefaults.init(suiteName: "MY_GROUP_NAME")!
let isFBConnected : Bool? = defaults.boolForKey("IsFacebookConnected")
if isFBConnected == nil {
return false
} else {
return isFBConnected!
}
}
set {
// Setting in UserDefaults
let defaults : NSUserDefaults = NSUserDefaults.init(suiteName: "MY_GROUP_NAME")!
defaults.setBool(newValue, forKey: "IsFacebookConnected")
defaults.synchronize()
}
}
This property is accessed from the App or from the Extension.
Then, in my Login / Logout methods I add :
//FBLogin
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
if let error = error {
print(error.localizedDescription)
return
}
if result.isCancelled
{
return
}
// Set in Shared UserDefaults if connected / not connected
ConfigManager.sharedInstance.isFacebookConnected = true
...
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
// OK, keeping track
ConfigManager.sharedInstance.isFacebookConnected = false
}
Then, I keep track of my flag when login / logout.
Warning : this method is not bullet proof as I can't know if Facebook has been uninstalled, but it is robust enough for me.
I believe you'll need to take advantage of Keychain sharing capability in the app and extension to solve this.
https://developer.apple.com/documentation/security/keychain_services/keychain_items/sharing_access_to_keychain_items_among_a_collection_of_apps

Logic hook displaying some information from parent record raises error

I've got an hosted instance of SugarCRM 6.5 CE, and one of the requirements I have to fulfil is to display some information--contact phone number, contact email address--of the parent record in an associated task/activity record.
All I found so far was pointing towards the creation of a logic hook for pulling the contact information from the parent record (Contacts) and display these in custom fields in the child record (Tasks).
Following some instructions and examples found I came up with the following as outlined below.
Under "custom/modules/Tasks" I've create a file called "logic_hooks.php"
<?php// $Id$
$hook_version = 1;
$hook_array = Array();
// debug
$GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
$GLOBALS['log']->debug("Task: logic hook invoked");
// position, file, function
$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array('1', 'contact_info', 'custom/modules/Tasks/hooks/contact_info.php','contact_info_class', 'contact_info_method');
?>
and under "custom/modules/Tasks/hooks" I've create a file called "contact_info.phplogic_hooks.php"
<?php
class contact_info_class {
// retrieve contact information from parent record
function contact_info_method($bean, $event, $arguments) {
// debug
$GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
$GLOBALS['log']->debug("Tasks: contact_info_method called for event ".$event . "(BeanID: " . $bean->id . ")");
// fetch data
if ($bean->fetched_row['id'] != $bean->id) {
// load Task
//$bean = BeanFactory::getBean('Tasks', $id);
// check if relationship is loaded
//if ($bean->load_relationship('contact_tasks_parent'))
if ($bean->load_relationship('contact_tasks')) {
// fetch related beans
//$relatedBeans = $bean->contact_tasks_parent->getBeans();
$relatedBeans = $bean->contact_tasks->getBeans();
$parentBean = false;
if (!empty($relatedBeans)) {
// order the results
reset($relatedBeans);
// first record in the list is the parent
$parentBean = current($relatedBeans);
// retrieve data from parent bean
$bean->contact_phone_c = $parentBean->phone_work
$bean->contact_primary_email_c = $parentBean->email1
}
}
}
} // contact_info_method
} // contact_info_class
?>
With this hook in place I can create new tasks without any problem at all, but when opening up an existing one, I'm receiving a message, reading
There was an error processing your request, please try again at a later time.
Being completely new to SugarCRM (btw. 6.5.20 CE it is I'm dealing with), I've got not the faintest idea as what is going wrong here.
I also cannot find any of the debug messages which are supposed to be written somewhere to.
--Sil68
The "contact_info.phplogic_hooks.php" file should be in the same folder as logic_hooks.php (custom/modules/< module-name>). And there's no need to name it that way (in fact I think it might cause problems). Try naming it just contact_info.php and changing the path given in the logic_hooks.php file to custom/modules/Tasks/contact_info.php.
As for where you can find the error log, assuming you're using apache for your web server (since you didn't specify) for linux/OS X, the error log is located at
/var/log/apache2/error.log
or
/var/log/apache2/error_log
In windows it'll be in
'C:\Program Files\Apache Software Foundation\Apache2.2\logs'.
Now that you know where the error log is, you can put
error_log('some helpful message');
inside your contact_info.php file and see which messages (if any) get sent to the error log. This can tell you if it even starts the logic hook and if so, how far it gets through the logic hook

authData column isn't updated properly on Parse.com for Anonymous users

I'm creating anonymous users from an iOS application using this code:
[PFAnonymousUtils logInWithBlock:^(PFUser *user, NSError *error) {
if (error)
{
NSLog(#"Anonymous login failed.");
} else
{
user.isAnonymous = true;
NSLog(#"Anonymous user logged in.");
}
}];
From time to time the authData column isn't populated with the "Anonymous" text and this means when I try to test if the user is anonymous it incorrectly reports that the user isn't anonymous.
As far as I know the column should be populated automatically and I'm not really sure why this happens.
This is how it looks:(There are more even more intercalated)
Do you have any idea why this happens?
Thanks.

Need help utilizing Beeblex validating in-app purchases with xCode

Has anyone had success using Beeblex to validate in-app purchases? I have an app that is already live in the app-store with in-app purchases enabled and working. In light of the recent hacking news concerning in-app purchases I am attempting to update it to use Beeblex to validate purchases. The problem is that Beeblex always returns a result saying that Apple claims the purchase to be invalid. I am hoping someone on here is successfully using Beeblex and can post a working example. I am following their advice to let the purchase go completely through, then validate it. I basically just cut and pasted their code right off their website, so not sure what I could do differently.
- (void) validatePurchaseOrRestore
{
//The transaction has been reported as complete for a new purchase of the upgrade. I now make use of Beeblex
//to verify the receipt to ensure the purchase is legit.
if (![BBXIAPTransaction canValidateTransactions])
{
transactionResult = 4;
return; // There is no connectivity to reach the server.
// You should try the validation at a later date.
}
BBXIAPTransaction *bbxTransaction = [[BBXIAPTransaction alloc] initWithTransaction:transactionCopy];
bbxTransaction.useSandbox;
[bbxTransaction validateWithCompletionBlock:^(NSError *error)
{
if (bbxTransaction.transactionVerified)
{
if (bbxTransaction.transactionIsDuplicate)
{
// The transaction is valid, but duplicate - it has already been
// sent to Beeblex in the past.
transactionResult = 1;
}
else
{
// The transaction has been successfully validated
// and is unique.
NSLog(#"Transaction data: %#", bbxTransaction.validatedTransactionData);
transactionResult = 0;
}
}
else
{
// Check whether this is a validation error, or if something
// went wrong with Beeblex.
if (bbxTransaction.hasServerError)
{
// The error was not caused by a problem with the data, but is
// most likely due to some transient networking issues.
transactionResult = 4;
}
else
{
// The transaction supplied to the validation service was not valid according to Apple.
transactionResult = 3;
purchaseDidFail = TRUE;
}
}
}];
}

Catching error with Usermanager.getUser() in Google Apps Script

I am working withing Google Spreadsheet creating a script file that has to deal with obtaining user information on my Google Apps Domain. I have admin rights and the Provisioning API is enabled. In my code, I am trying to catch the error when looking up a specific user on a Google Apps Domain (user not found) and instead display a message and continuing on with the rest of the program. The try-catch statement I have here works when there is no error on the user. However, when there is an error on retrieving the user, I get the error: "Unexpected exception upon serializing continuation". Here is my code:
function testOfDomainAccess() {
var i=0;
var anArray= ["johhn.smith", "susan.que]; //john smith misspelled
var user;
for (i=0; i < anArray.length; ++i)
{
Logger.log("\nThe current user being processed is " + anArray[i]);
try
{
user = UserManager.getUser (anArray [i]);
}
catch (error)
{
Browser.msgBox("Error: " + error.name + "\n Check your spreadsheet for misspellings of " + anArray[i] + " and We will continue to the next user.");
user = null;
}
if (user != null) {
//Perform tasks
}
else
Logger.log("User not found in domain. Moving on the next item in the array.");
}
If anyone can help with this problem I would greatly appreciate it. I am new to Google Apps Script and Provisioning API. Thanks!
It looks like the same bug reported at http://code.google.com/p/google-apps-script-issues/issues/detail?id=980.
The workaround is to replace the Browser.msgBox() call with Logger.log() and your script should run as expected.

Resources