RestKit 0.2 — Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 - restkit

I just updated to RestKit 0.20 and I'm beating my head against my desk top trying to figure what why my Album object won't map. The response object doesn't have a keyPath — but setting it to #"" worked before.
Here is a snippet of the data coming back:
[
{
id: "337",
title: "Hockey",
description: "",
location: "",
date_created: "1353424563",
date_modified: "1353424563",
featured_image: "album_default.png",
featured_thumb_link: "http://test1.keepsayk.com//images/album_default.jpg",
featured_main_link: "http://test1.keepsayk.com/img/album_default.png",
feat_img_type: "image",
public: "0",
default_album: "",
owner_fname: "Mike",
owner_lname: "Rose",
owner_id: "102",
recent_media: false,
last_media_added_date: false,
tags: [ ],
circles: [],
media: [ ],
image_count: 0,
video_count: 0,
text_count: 0,
audio_count: 0,
comments: [ ],
scrapbook: [ ]
},
{
id: "336",
title: "Bull",
description: "",
location: "",
date_created: "1353420585",
date_modified: "1353420585",
featured_image: "album_default.png",
featured_thumb_link: "http://test1.keepsayk.com//images/album_default.jpg",
featured_main_link: "http://test1.keepsayk.com/img/album_default.png",
feat_img_type: "image",
public: "0",
default_album: "",
owner_fname: "Mike",
owner_lname: "Rose",
owner_id: "102",
recent_media: false,
last_media_added_date: false,
tags: [ ],
circles: [],
media: [ ],
image_count: 0,
video_count: 0,
text_count: 0,
audio_count: 0,
comments: [ ],
scrapbook: [ ]
},
...
]
Here is my code in the App Delegate:
// restkit object manager
_objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:#"http://test1.keepsayk.com"]];
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
// restkit object store
_objectManager.managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:[self managedObjectModel]];
[_objectManager.managedObjectStore createPersistentStoreCoordinator];
[_objectManager.managedObjectStore createManagedObjectContexts];
// setup album object
RKEntityMapping *albumEntityMapping = [RKEntityMapping mappingForEntityForName:#"KeepsaykAlbum" inManagedObjectStore:_objectManager.managedObjectStore];
albumEntityMapping.identificationAttributes = #[#"identifier"];
[albumEntityMapping addAttributeMappingsFromDictionary:#{ #"id" : #"identifier", #"title" : #"keepsaykTitle", #"description" : #"keepsaykDescription", #"date_created" : #"dateCreated", #"date_modified" : #"dateModified", #"featured_thumb_link" : #"featuredImageThumbLink", #"featured_main_link" : #"featuredImageLink", #"public" : #"isPublic", #"default_album" : #"isDefaultAlbum", #"owner_fname" : #"ownerFirstName", #"owner_lname" : #"ownerLastName", #"owner_id" : #"ownerIdentifier", #"last_media_added_date" : #"dateMediaModified", #"image_count" : #"imageCount", #"video_count" : #"videoCount", #"text_count" : #"textCount", #"audio_count" : #"audioCount", #"scrapbook" : #"scrapbookLayouts" }];
[_objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:albumEntityMapping pathPattern:#"albums/display/:userID/:apiKey" keyPath:#"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
I call the get method in another class — the resource path is traced in the log:
- (void)loadObjectsFromResourcePath:(NSString *)resourcePath;
{
NSLog(#"resource path: %#", resourcePath);
[RKObjectManager.sharedManager getObjectsAtPath:resourcePath parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(#"mapping result: %#", [mappingResult array]);
[self stopLoading];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"error: %#", error);
[self stopLoading];
}];
}
Here is my error log:
2012-12-04 17:48:47.437 Keepsayk Alpha[9036:907] I restkit:RKLog.m:34 RestKit logging initialized...
2012-12-04 17:48:47.703 Keepsayk Alpha[9036:907] I restkit.support:RKMIMETypeSerialization.m:115 JSON Serialization class 'RKNSJSONSerialization' detected: Registering for MIME Type 'application/json
2012-12-04 17:48:47.696 Keepsayk Alpha[9036:907] resource path: albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba
2012-12-04 17:48:47.708 Keepsayk Alpha[9036:1603] I restkit.network:RKHTTPRequestOperation.m:141 GET 'http://test1.keepsayk.com/albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba'
2012-12-04 17:48:47.711 Keepsayk Alpha[9036:907] error (null), (null)
2012-12-04 17:48:48.995 Keepsayk Alpha[9036:372f] I restkit.network:RKHTTPRequestOperation.m:158 GET 'http://test1.keepsayk.com/albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba' (200)
2012-12-04 17:48:49.011 Keepsayk Alpha[9036:907] error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "Unable to find any mappings for the given content" UserInfo=0x1d5b7e40 {DetailedErrors=(
), NSLocalizedDescription=Unable to find any mappings for the givn content, keyPath=null}

Set the keyPath to nil instead of #""

I was missing the initial "/" in my resource path.
[_objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:albumEntityMapping pathPattern:#"/albums/display/:userID/:apiKey" keyPath:#"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];

If anyone still gets this error, please check your "/" so when combining the baseURL and your paths you don't end up with "www.mybase.com//blah/blah.json". Also, if you update to the latest Restkit code, as of 12/8/2012 you should get a slight fix. Blake has added code to warn with a better descriptive than 1001 during runtime.

Related

IOS SWIFT PARSE : Pfcloud.callFunction

i have an old app in objective C using cloudcode to send pushes to back4app platform.
The app manage to send correctly the pushes and this is the code :
- (IBAction)inviaPush:(UIButton *)sender {
NSString *canale;
for (int i=0; i<=4; i++) {
switch (i) {
case 0:canale=#"TraduzioniEDI";
break;
case 1:canale=#"NavFtpYM";
break;
case 2:canale=#"InvioMailFTP";
break;
case 3:canale=#"VermasMto";
break;
case 4:canale=#"EdiAltova";
break;
default:
break;
}
NSString *testoPush =[NSString stringWithFormat:#"%# Test Invio %#", canale,[NSDate date]];
[PFCloud callFunctionInBackground:#"push"
withParameters:#{#"channels": #[canale], #"data": #{#"alert": testoPush,#"badge":#"Increment"}}
block:^( NSString *result, NSError *error) {
if (!error) {
NSLog(#"Risultato: %#",result);
} else{
NSLog(#"Errore %#",error);
}
}];
}
}
Running the code i receive the 5 pushes and in the info of back4app dashboard i find :
2020-03-02T01:14:53.533Z - Ran cloud function push for user undefined with:
Input: {"channels":["VermasMto"],"data":{"alert":"VermasMto Test Invio 2020-03-02 01:14:52 +0000"}}
Result: "Sent!!"
i tried to convert the program in swift
the code to send push is :
func inviaPush (){
var canale :String = ""
for i in 0...4
{
switch i {
case 0: canale = "TraduzioniEDI"
case 1: canale = "NavFtpYM"
case 2: canale = "InvioMailFTP"
case 3: canale = "VermasMto"
case 4: canale = "EdiAltova"
default: canale=""
}
let testoPush = "\(canale) Test invio - Swift"
PFCloud.callFunction(inBackground: "push", withParameters: ["channels": canale, "data": ["alert": testoPush,"badge":"Increment"]], block: {
(result: Any?, error: Error?) -> Void in
if error != nil {
if let descrip = error?.localizedDescription{
print(descrip)
}
}else{
print(result as! String)
}
})
}
}
in this case i receive no pushes, and in the info i find following :
2020-03-02T01:17:25.505Z - Ran cloud function push for user undefined with:
Input: {"channels":"NavFtpYM","data":{"alert":"NavFtpYM Test invio"}}
Result: "Sent!!"
2020-03-02T01:17:25.504Z - Can't count installations for PushStatus hm5hbCzDvd: bad $in value
Comparing the info shown in the dashboard i see a difference in input
in ojective C (Working) the in input the channel have a square bracket :
Input: {"channels":["VermasMto"],
while when sent from swift they have not
Input: {"channels":"NavFtpYM",
surely i'm calling the method PFCloud.callFunction in a wrong way.
Any suggestion ?
Fabrizio
the solution was simple ...
need to change
PFCloud.callFunction(inBackground: "push", withParameters: ["channels": canale, "data": ["alert": testoPush,"badge":"Increment"]], block: {
in
PFCloud.callFunction(inBackground: "push", withParameters: ["channels": [canale], "data": ["alert": testoPush,"badge":"Increment"]], block: {
Fabrizio

How to do multi-level pull of array element in mgo?

I want to do a multi-level array element delete. My Structs are as follows:-
type Company struct {
Id bson.ObjectId `bson:"_id,omitempty"`
CompanyName string
Process []ProcessItem
}
type ProcessItem struct{
SortOrder int
Documents []DocumentTemplate
}
type DocumentTemplate struct {
Id bson.ObjectId `bson:"_id,omitempty"`
TemplateName string
}
I want to delete an object of type DocumentTemplate. The DocumentTemplate is a struct array in ProcessItem which is a struct array in Company struct. I have Company Id(field of struct Company) and TemplateName(field of struct DocumentTemplate).
I tried the below mgo pull query but it is not working.
c := db.C("company")
pullQuery := bson.M{"process": bson.M{"documents.templatename": "xyz"}}
err := c.Update(bson.M{"_id": "123"}, bson.M{"$pull": pullQuery})
Please point out the mistakes I made here. Thanks.
Edit:
Adding one example document for the clarity of the question
{
"_id" : ObjectId("573da7dddd73171e42a84045"),
"companyname" : "AAA",
"process" : [
{
"processname" : "Enquiry",
"sortorder" : 0,
"documents" : [
{
"templatename" : "xyz",
"processname" : "Enquiry"
},
{
"templatename" : "ss",
"processname" : "Enquiry"
}
]
},
{
"processname" : "Converted",
"processtype" : 1,
"sortorder" : 2,
"documents" : [
{
"templatename" : "dd",
"processname" : "Converted"
},
{
"templatename" : "fg",
"processname" : "Converted"
}
]
}
]
}
I need to pull out just one DocumentTemplete record, like the one below:
{
"templatename" : "xyz",
"processname" : "Enquiry"
}
N.B: TemplateName will be unique inside a Company.
You'll need to use the $ positional operator (https://docs.mongodb.com/manual/reference/operator/projection/positional/). In order to be able to use that you'll also have to add to your query the following:
"process.documents.templatename": "xyz"
Your Update statement should look like this:
c := db.C("company")
pullQuery := bson.M{"process.$.documents": bson.M{"templatename": "xyz"}}
err := c.Update(bson.M{"_id": "123", "process.documents.templatename": "xyz"}, bson.M{"$pull": pullQuery})
You can pull values in array from the array in mongo record
change2 := bson.M{
"$pull": bson.M{"sapinfo.systemstatus": bson.M{"$in": tags}},
}

Error with 'getProfilePicture'

I have a profile view controller where the user can set or change his or her profile picture but am getting constant errors that do not make sense to me.
-(void)getProfilePicture
{
PFUser *user = [PFUser currentUser];
NSLog(#"file--%#",[user objectForKey:PF_USER_PICTURE]);
userName = user[PF_USER_USERNAME];
status = user[PF_USER_STATUS];
if ([user objectForKey:PF_USER_PICTURE]) {
[imageUser setFile:[user objectForKey:PF_USER_PICTURE]];
[imageUser loadInBackground];
}
else{
imageUser.image = [UIImage imageNamed:#"blank_profile#2x.png"];
}
// fieldName.text = user[PF_USER_FULLNAME];
}
#pragma mark - UIActionSheetDelegate
I receive the following errors portrayed in my ProfileViewController.m (I can provide/add .h if needed):
"No visible #interface for 'UIImageView' declares the selector 'setFile:'
"No visible #interface for 'UIImageView' declares the selector 'loadInBackground'
Any help would be much appreciated or any supporting code thats needed, thanks.
Try this and see what it does for you:
-(void)getProfilePicture
{
PFUser *user = [PFUser currentUser];
NSLog(#"file--%#",[user objectForKey:PF_USER_PICTURE]);
userName = user[PF_USER_USERNAME];
status = user[PF_USER_STATUS];
if ([user objectForKey:PF_USER_PICTURE]) {
userImage.file = [user objectForKey:PF_USER_PICTURE];
[userImage loadInBackground:^(UIImage *image, NSError *error) {
if (!error) {
imageUser.image = image;
[imageUser setNeedsDisplay];
} else {
NSLog(#"%#", error);
}
}];
}
else{
imageUser.image = [UIImage imageNamed:#"blank_profile#2x.png"];
}
// fieldName.text = user[PF_USER_FULLNAME];
}
#pragma mark - UIActionSheetDelegate
This is assuming your userImage is a PFImageView and [user objectForKey:PF_USER_PICTURE] is a PFFile.
EDIT
Actually, looking at your error it seems that userImage is just a UIImageView not a PFImageView, which might be the source of all your problems. Try making the userImage a PFImageView

Get "GeneratedUID" programmatically in COCOA

I'm trying to get system GeneratedUID programmetically, i'm able to get the UID from command line using "dscl . -search /Users GeneratedUID 00052AE8-5000-6000-9007-666F6B666A66"
Can anyone help how to get this GeneratedUID programmetically?
This worked for me. It returns the first GeneratedUID that it finds for the current user, or nil if none are found.
There are lots of errors to handle, making the logic more complicated than it really should be.
-(NSString*) getGeneratedUID {
NSString* retval = nil;
ODSession *mySession = [ODSession defaultSession];
NSError *err;
ODNode *myNode = [ODNode nodeWithSession:mySession type:kODNodeTypeAuthentication error:&err];
NSString* username = NSUserName();
ODQuery *myQuery = [ODQuery queryWithNode: myNode
forRecordTypes: kODRecordTypeUsers
attribute: kODAttributeTypeRecordName
matchType: kODMatchEqualTo
queryValues: username
returnAttributes: kODAttributeTypeStandardOnly
maximumResults: 0
error: &err];
if (err) {
NSLog(#"Error creating current user query: %#", [err localizedDescription]);
}
else {
NSArray* queryResults = [myQuery resultsAllowingPartial:NO error:&err];
if (err) {
NSLog(#"Error executing current user query: %#", [err localizedDescription]);
}
else {
if ( [queryResults count] > 0 ) {
ODRecord* firstQueryResult = [queryResults objectAtIndex:0];
NSArray* uidValues = [firstQueryResult valuesForAttribute:#kDS1AttrGeneratedUID error:&err];
if (err) {
NSLog(#"Error getting GeneratedUID attribute for current user: %#", [err localizedDescription]);
}
else {
if ([uidValues count] > 0) {
retval = (NSString*) [uidValues objectAtIndex:0];
}
else {
NSLog(#"No GeneratedUID values for current username: %#", username);
}
}
}
else {
NSLog(#"No results from current user query for username: %#", username);
}
}
}
return retval;
}
just use the following code to retrive UID.... import the SecurityConfiguration.framework before you add the code..
NSString* GetConsoleUser(uid_t* p_uid, gid_t* p_gid) {
NSString* name = (NSString*)CFBridgingRelease(SCDynamicStoreCopyConsoleUser(
NULL, p_uid, p_gid));
return name ;
}
you have to play around the string to get the "UID".

Mapping XML succeeds but object has empty values

I'm using RKXMLReaderSerialization and trying to map an XML response from my server to an object. It succeeds, but the object from the mapping result just has empty values.
Here's the text/xml response I'm trying to map from my server:
<Provision version="1.0">
<FileInfoWrapper>
<FileUrl>SomeFile.zip</FileUrl>
<FileName>SomeFile.zip</FileName>
<FileSha1>oi7NK/rFLL6dXqcu7ahaNfKsGkE=</FileSha1>
<FileSize>52220448</FileSize>
<Version>13</Version>
<Vital>true</Vital>
</FileInfoWrapper>
</Provision>
Here's my model object:
#interface FileInfoWrapper : NSObject
#property NSString *fileUrl;
#property NSString *fileName;
#property NSString *fileSha1;
#property long fileSize;
#property NSString *version;
#property BOOL vital;
#end
I've added RKXMLReaderSerialization:
[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:RKMIMETypeTextXML];
[[self objectManager] setAcceptHeaderWithMIMEType:#"application/json,text/xml"];
I think I have the mapping and response descriptor setup correctly:
RKObjectMapping *fileInfoMapping = [RKObjectMapping mappingForClass:[FileInfoWrapper class]];
[fileInfoMapping addAttributeMappingsFromDictionary:#{
#"FileUrl": #"fileUrl",
#"FileName": #"fileName",
#"FileSha1": #"fileSha1",
#"FileSize": #"fileSize",
#"Version": #"version",
#"Vital": #"vital"}];
RKResponseDescriptor *fileInfoResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:fileInfoMapping
method:RKRequestMethodGET
pathPattern:nil
keyPath:#"Provision.FileInfoWrapper"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[self objectManager] addResponseDescriptor:fileInfoResponseDescriptor];
But when I call:
[[self objectManager] getObjectsAtPath:#"static/download/Installer.info.xml"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(#"****Success!****");
NSLog(#"mappingResult: %#", mappingResult);
FileInfoWrapper *fileInfo = [mappingResult firstObject];
NSLog(#"URL: %#", [fileInfo fileUrl]);
NSLog(#"Name: %#", [fileInfo fileName]);
NSLog(#"SHA1: %#", [fileInfo fileSha1]);
NSLog(#"Size: %lx", [fileInfo fileSize]);
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"****Failure!****");
}];
All the values are null:
I restkit.network:RKObjectRequestOperation.m:180 GET 'http://example.com/static/download/Installer.info.xml'
I restkit.network:RKObjectRequestOperation.m:250 GET 'http://example.com/static/download/Installer.info.xml' (200 OK / 1 objects) [request=0.1080s mapping=0.0060s total=0.1226s]
****Success!****
mappingResult: <RKMappingResult: 0x10064b190, results={
"Provision.FileInfoWrapper" = "<FileInfoWrapper: 0x10065f780>";
}>
URL: (null)
Name: (null)
SHA1: (null)
Size: 0
What am I doing wrong?
UPDATE: I turned on RestKit/ObjectMapping logging and got some additional info:
D restkit.object_mapping:RKMapperOperation.m:377 Executing mapping operation for representation: {
Provision = {
FileInfoWrapper = {
FileName = {
text = "SomeFile.zip";
};
FileSha1 = {
text = "oi7NK/rFLL6dXqcu7ahaNfKsGkE=";
};
…
}
and targetObject: (null)
T restkit.object_mapping:RKMapperOperation.m:320 Examining keyPath 'Provision.FileInfoWrapper' for mappable content...
D restkit.object_mapping:RKMapperOperation.m:300 Found mappable data at keyPath 'Provision.FileInfoWrapper': {
FileName = {
text = "SomeFile.zip";
};
FileSha1 = {
text = "oi7NK/rFLL6dXqcu7ahaNfKsGkE=";
};
…
}
D restkit.object_mapping:RKMapperOperation.m:231 Asked to map source object {
FileName = {
text = "SomeFile.zip";
};
FileSha1 = {
text = "oi7NK/rFLL6dXqcu7ahaNfKsGkE=";
};
…
} with mapping <RKObjectMapping:0x10025e6b0 objectClass=FileInfoWrapper propertyMappings=(
"<RKAttributeMapping: 0x10025ebc0 FileSha1 => fileSha1>",
"<RKAttributeMapping: 0x10025ed90 FileName => fileName>"
…
)>
D restkit.object_mapping:RKMappingOperation.m:952 Starting mapping operation...
T restkit.object_mapping:RKMappingOperation.m:953 Performing mapping operation: <RKMappingOperation 0x10068f730> for 'FileInfoWrapper' object. Mapping values from object {
FileName = {
text = "SomeFile.zip";
};
FileSha1 = {
text = "oi7NK/rFLL6dXqcu7ahaNfKsGkE=";
};
…
} to object <FileInfoWrapper: 0x10068f290> with object mapping (null)
T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'FileUrl' to 'fileUrl'
T restkit.object_mapping:RKMappingOperation.m:431 Found transformable value at keyPath 'FileUrl'. Transforming from type '__NSDictionaryM' to 'NSString'
D restkit.object_mapping:RKPropertyInspector.m:130 Cached property inspection for Class 'FileInfoWrapper': {
fileName = {
isPrimitive = 0;
keyValueCodingClass = NSString;
name = fileName;
};
fileSha1 = {
isPrimitive = 0;
keyValueCodingClass = NSString;
name = fileSha1;
};
…
}
T restkit.object_mapping:RKMappingOperation.m:583 Skipped mapping of attribute value from keyPath 'FileUrl to keyPath 'fileUrl' -- value is unchanged ((null))
T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'FileSha1' to 'fileSha1'
T restkit.object_mapping:RKMappingOperation.m:431 Found transformable value at keyPath 'FileSha1'. Transforming from type '__NSDictionaryM' to 'NSString'
T restkit.object_mapping:RKMappingOperation.m:583 Skipped mapping of attribute value from keyPath 'FileSha1 to keyPath 'fileSha1' -- value is unchanged ((null))
…
It appears that you have to map from the text node. This post had the same problem:
RestKit 0.20-pre3 with RKXMLReaderSerialization and XMLReader
Changing the mapping to:
[fileInfoMapping addAttributeMappingsFromDictionary:#{
#"FileUrl.text": #"fileUrl",
#"FileName.text": #"fileName",
#"FileSha1.text": #"fileSha1",
#"FileSize.text": #"fileSize",
#"Version.text": #"version",
#"Vital.text": #"vital",}];
did it.
You shouldn't set the accept header to JSON if you're expecting XML. I also don't think you can set a comma separated list like that (not 100% sure on that though). If the server sends JSON as a result of your accept header then RestKit will be happy with the response but will likely fail to actually do any mapping (which appears to be what you see).
Turn on trace logging to get more info about the response and the mapping:
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
Your mapping code does look correct.

Resources