Facebook open graph object ,,, can't set its properties - ios

I have successfully post the object on my wall with its default values for the properties.
What I need to do now is setting these properties for that object manually through my code.
Here is what I have done:
#protocol OGApple<FBOpenGraphAction>
#property (nonatomic, retain) NSString *url;
#property (nonatomic, retain) NSString *title;
#property (nonatomic, retain) NSString *image;
#property (nonatomic, retain) NSString *description;
#end
#protocol OGEatAction<FBOpenGraphAction>
#property (retain, nonatomic) id<OGApple> apple;
#end
the object "apple" here has four required properties (url, title, image, description) ,,, here is how I set them :
Define the object:
id<OGApple> graphObject = (id<OGApple>)[FBGraphObject graphObject];
Define the action:
id<OGEatAction> action = (id<OGEatAction>)[FBGraphObject graphObject];
set the properties (I have try method 1 and two) none of them set the object property :
Method one:
[graphObject setObject:#"The Game" forKey:#"title"];
[graphObject setObject:#"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png" forKey:#"image"];
[graphObject setObject:#"http://samples.ogp.me/267255650070428" forKey:#"url"];
Method two:
graphObject.url = #"http://samples.ogp.me/267255650070428";
graphObject.title = #"Mohammad";
graphObject.image = #"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png";
then assign the object to the action:
action.apple = graphObject;
then POST the request
[FBRequestConnection startForPostWithGraphPath:#"me/theapp:eat"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
// handle the result
if(error)
NSLog(#"%#", error);
else
NSLog(#"%#", result);
}];
The request successfully posted and return id = xxxxxxxxxx
But on my timeline the object not take the parameters that I have passed to it!
Did I miss something or need any extra config on a server?
Thanks in advance :)

Related

iOS: Object returns nil description after alloc and init

Object returns nil description after alloc and init..can any one tell me i have to display the data which comes from server...when i clicks on edit button it goes to shoow room class in that class.. inside textfields hav to display the information .can any one help me
#interface HeadOfficeDetails : NSObject
#property(nonatomic,strong) NSMutableArray *ofcContact;
#property(nonatomic,strong) OfficeDocument *ofcDocument;
#property(nonatomic,strong) OfficePrice *ofcPrice;
#property(nonatomic,strong) CityClass *city;
#property(nonatomic,strong) StateClass *state;
#property(nonatomic,strong) DistrictClass *district;
#property(nonatomic,strong)NSString *shrtname;
#property(nonatomic,strong)NSString *shwrmname;
#property(nonatomic,strong)NSString *shop;
#property(nonatomic,strong)NSString *door;
#property(nonatomic,strong)NSString *buildng;
#property(nonatomic,strong)NSString *flr;
#property(nonatomic,strong)NSString *tele;
#property(nonatomic,strong)NSString *pin;
#property(nonatomic,strong)NSString *main;
#property(nonatomic,strong)NSString *dist;
#property(nonatomic,strong)NSString *designan;
#property(nonatomic,strong)NSString *depart;
#property(nonatomic,strong)NSString *emai;
#property(nonatomic,strong)NSString *mobile;
#property(nonatomic,strong)NSString *strt;
#property(nonatomic,strong)NSString *area;
#property(nonatomic,strong) NSString *jwleryname;
#property(nonatomic,strong) NSString *officeid;
-(void)setAttributes:(NSDictionary *)attributes;
///////////////////////////////////////////////
showroom class
headdetails=[[HeadOfficeDetails alloc]init];
self.txtshowroom.text=headdetails.jwleryname;
NSLog(#"%# :",self.txtshowroom.text);
NSNumber *officeid=headdetails.officeid;
NSLog([NSString stringWithFormat:#"%#",officeid]);
[self.txtshortname setText:headdetails.jwleryname];
[self.txtshowroom setText:headdetails.shwrmname];
[self.txtstreet setText:headdetails.strt];
[self.txtarea setText:headdetails.area];
[self.txtmain setText:headdetails.main];
[self.txtbuilding setText:headdetails.buildng];
[self.txtname setText:self.cntctcls.contactname];
[self.txtdesign setText:self.cntctcls.desig];
[self.txtdepartmnt setText:self.cntctcls.depart];
[self.txtmbl setText:self.cntctcls.mobile];
[self.txtemail setText:self.cntctcls.email];
[self.txtfloor setText:headdetails.flr];
[self.txttel setText:headdetails.tele];
[self.txtpincode setText:headdetails.pin];
[self.txtshop setText:headdetails.shop];
Here are i put example code for show NSObject class data that save during data fetch from server and show on another class by using its instance.
Following is create a NSObject class for storing FBLogin userDetauls:
#import <Foundation/Foundation.h>
#interface FBUser : NSObject
#property (nonatomic,strong) NSString *FBUserId;
#property (nonatomic,strong) NSString *FBUserName;
#property (nonatomic,strong) NSString *FBUserFirstName;
#property (nonatomic,strong) NSString *FBUserLasttName;
#property (nonatomic,strong) NSString *FBUserEmail;
#property (nonatomic,strong) NSString *FBUserBio;
#property (nonatomic,strong) NSString *FBUserLocation;
+(instancetype)SharedFBUser;
-(void)ClearFBuser;
+(NSString*)CheckEmtryElseAlert:(NSString*)strValue;
#end
Following is an Implementation class here we create SharedFBUser that allcate FBUser object once if that found nil so when no need to do code alloc init during show time
#import "FBUser.h"
static FBUser* fbObject;
#implementation FBUser
+(instancetype)SharedFBUser
{
if(fbObject == nil)
{
fbObject =[[FBUser alloc]init];
}
return fbObject;
}
-(void)ClearFBuser
{
fbObject = nil;
self.FBUserId = nil;
self.FBUserName = nil;
self.FBUserFirstName =nil;
self.FBUserLasttName = nil;
self.FBUserEmail = nil;
self.FBUserBio = nil;
self.FBUserLocation = nil;
}
Now following code for how to use FBUser class for save data .H class:
#import <UIKit/UIKit.h>
#import "FBUser.h"
#interface LoginViewController : UIViewController
#property(nonatomic,strong)FBUser *fbObject;
#end
And you can save data in FBCallback:
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me" parameters:#{#"fields": #"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(#"resultis:%#",result);
[FBUser SharedFBUser].FBUserId =[result valueForKey:#"id"];
[FBUser SharedFBUser].FBUserEmail =[result valueForKey:#"email"];
[FBUser SharedFBUser].FBUserName =[result valueForKey:#"name"];
[FBUser SharedFBUser].FBUserFirstName =[result valueForKey:#"first_name"];
[FBUser SharedFBUser].FBUserLasttName =[result valueForKey:#"last_name"];
}
else
{
NSLog(#"Error %#",error);
}
}];
And following code for show the data that have stored in FBuser class
#import "FBUser.h"
self.lblEmail.text = [FBUser SharedFBUser].FBUserEmail;
self.lblusename.text = [FBUser SharedFBUser].FBUserName;
self.lblfirstname.text = [FBUser SharedFBUser].FBUserFirstName;
self.lbllastname.text = [FBUser SharedFBUser].FBUserLasttName;
Hope that help this fully description about use and create. this is my working code.
Not sure what are you doing, may you need something like parse dictionary to object first.
headdetails=[[HeadOfficeDetails alloc]init];
New Object created so all properties will nil.
you need assign value for it like
headdetails=[[HeadOfficeDetails alloc]initWithDictionary:attributes];
You can parse it your self or looking some 3rd library like:JSonModel

Mantle modelOfClass json parsing

I have the following Mantle object & want to convert the dictionary to Mantle object. but the conversion always returns empty MTLModel object.
Any ideas?
//ABC.h
#interface ABC : MTLModel<MTLJSONSerializing>
#property (nonatomic, strong) NSString *Identifier;
#property (nonatomic, strong) NSString *Name;
#property (nonatomic, strong) NSString *ImageURLString;
#property (nonatomic, strong) NSString *Desc;
#property (nonatomic, strong) NSString *lastUpdated;
#end
// ABC.m
#implementation ABC
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return #{
#"Identifier" : #"id",
#"Name" : #"name",
#"Desc" : #"desc",
#"ImageURLString" : #"image_url",
#"lastUpdated" : #"last_updated_at"
};
}
#end
Calling code:
ABC *abc = [MTLJSONAdapter modelOfClass:ABC.class fromJSONDictionary:tempDict error:NULL];
The JSON dictionary is:
{
desc = "asdadasdakjqewqwmsdnasdaksdasd";
id = adsasdasdasdasd;
"image_url" = "http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/abc.JPG";
"last_updated_at" = "2015-07-25 04:22:39.851710";
name = asdasdqwe;
}
The result ABC object has no contents. Can't figure what I am missing here.
Any ideas???
Try with this snippet and debug the adapterError. May have relevant information about the conversion from NSDictionary to Mantle object
//Create Mantle object from NSDictionary using MTLJSONSerialization
NSError *adapterError;
MTLModel *user = [MTLJSONAdapter modelOfClass:MTLModel.class fromJSONDictionary:dictionary error:&adapterError];
if(adapterError) {
PrintError(adapterError)
return nil;
}
id = adsasdasdasdasd;
needs to be
id = "adsasdasdasdasd";

RKMappingResult has objects, but they NSLog as null

What I'm doing
Using RestKit, I'm making a GET request to get a JSON object that contains an array of User objects that populate a UITableView. I pass that array into a private NSArray called users which becomes _users (I'm still fuzzy on this). This works, and the table populates fine. I can access the individual objects in the _users array from my other methods, such as [UITableViewCell cellForRowAtIndex].
However, at the same time I pull the data down, and before I call [self.tableView reloadData] from inside the success block of [RKObjectManager getObjectsAtPath...], I want to process the individual objects a little bit.
My problem
Using [RKObjectManager getObjectsAtPath parameters success failure], success returns the RKMappingResult as expected, and I pass its array to a _users, which populates my UITableView. This works, but in the same success block, I try NSLog'ing _users[i] and it returns *nil description*. I know the values are being set at some point, because I populate my UITableViewCells by calling _users[i] in another method.
Hopefully more helpful info
When I NSLog(#"%#", _users) from inside the success block, and know for a fact there are 3 objects in the array, I see:
(
(null),
(null),
(null)
).
I can provide more info, I'm just not sure what to put. I can also show my code, but it's basically out of the book from the RestKit docs.
User object
#interface User : NSObject
#property (nonatomic, strong) NSString *id;
#property (nonatomic, strong) NSString *email;
#property (nonatomic, strong) NSString *username;
#property (nonatomic, strong) NSString *fullName;
#property (nonatomic, strong) NSString *bio;
#property (nonatomic) NSDate *dob;
#property (nonatomic, strong) NSString *avatar;
#property (nonatomic, strong) NSString *avatarMeta;
#property (nonatomic, strong) NSString *location;
#property (nonatomic, strong) NSURL *url;
#property (nonatomic, strong) NSString *enabled;
#end
RKObjectManager example
*note - some pieces have been removed for security reasons
- (void)loadUsers {
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:#{#"token": self.token}];
NSString *path = #"/api/v1/g/feed";
if ( self.cursor ) {
path = [NSString stringWithFormat:#"%#/%#", path, self.cursor];
}
[[RKObjectManager sharedManager] getObjectsAtPath:path
parameters:params
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
_users = mappingResult.array;
NSLog(#"Last User: %#",_users[0]); // *nil description*
NSLog(#"Array: %#", _users); // ((null),(null),(null),(null),(null),(null),(null),(null),(null),(null))
[self.tableView reloadData]; // table gets populated correctly
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(#"No feed available: %#", error);
}];
}
Most likely you're overriding the description method, probably by adding your own property with that name, in the user class and setting that to an empty string. This breaks everything. You should rename that property to overview or something like that and update your usage.

NString value of custom object gets lost after segue (Objective C)

Heyo Guys
So I am more or less new to Objective C and got to a problem which I seem unable to solve.
I created a class called "Students" which all have a name surname etc. All those Students are put into a NSMutableArray (before they get created from JSON , that seems to work without a problem though). Then all the names of the students are put into a ListView. Afterwards when a name is clicked (segue passes the object), one should see the details of said student (i.e. his full name, his id, his street).
The problem is that all the string values of the student object seem to get lost.
I checked that all the student object work just fine. I think the problem lies at the #property in my student class.
Any comments and suggestions are appreciated
This is an excerpt of student.h As said only the string values get lost, the int (here the plz value) remains correct
#property (nonatomic, weak)NSString *lastname;
#property (nonatomic, weak)NSString *surname;
#property (nonatomic, weak)NSString *street;
#property (nonatomic, assign)int plz;
EDIT:
Here is where i parse my json.
for (NSDictionary *dic in jsonArray){
NSNumber *identity = [dic valueForKey:#"id"] ;
NSString *firstName = (NSString*) [dic valueForKey:#"first_name"];
NSString *lastName = (NSString*) [dic valueForKey:#"last_name"];
NSString *street = (NSString*) [dic valueForKey:#"street"];
NSNumber *plz = [dic valueForKey:#"plz"] ;
NSString *birth = (NSString*) [dic valueForKey:#"date_of_birth"];
NSArray *bills = dic[#"bills"];
NSArray *hours = dic[#"hours"];
NSLog(#"First %#",firstName);
Student *student = [[Student alloc]initWithLastName:lastName withSurname:firstName withStreet:street withPLZ:plz withOrt:#"Uitikon" withBirthDate:birth withOccupation:#"Schüler"];
[ApprenticeList addObject:student];
}
EDIT 2 :
I found out that the string values get lost even before the segue. All these objects are created in
ViewDidLoad
But in
prepareforsegue
all the values are allready null (except for the int) .So the only place where the student objects work is in
ViewdidLoad
#property (nonatomic, weak)NSString *lastname;
#property (nonatomic, weak)NSString *surname;
#property (nonatomic, weak)NSString *street;
change to
#property (nonatomic, strong)NSString *lastname;
#property (nonatomic, strong)NSString *surname;
#property (nonatomic, strong)NSString *street;
You can also use 'copy'. It will cause the setter for that property to create a copy of the object, otherwise it is identical to strong.

Query Amazon DynamoDB for specific result

I am using the DynamoDB SDK v2 . I can scan the database however I am struggling to query it for a specific results. I don't know if I have the DB setup wrong or I am doing the query wrong.
When I use
- (void)getTableRow:(NSString *)rangeKey {
AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
[[dynamoDBObjectMapper load:[SonicUserTableRow class]
hashKey:#"UserId"
rangeKey:rangeKey] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
if (!task.error) {
SonicUserTableRow *tableRow = task.result;
NSLog (#"Table Row %#", tableRow);
} else {
//Catch Error
}
return nil;
}];
}
I am calling it using [self getTableRow:#" ENTER UNIQUE USER ID "];
However I am getting the error
The provided key element does not match the schema
How can I fix this?
Note I am using the new Amazon SDK v2.
My Database
HASH & RANGE KEYS
SonicUserTableRow .m
+ (NSString *)dynamoDBTableName {
return #"SonicUsers";
}
+ (NSString *)hashKeyAttribute {
return #"UserId";
}
+ (NSString *)rangeKeyAttribute {
return #"Username";
}
SonicUserTableRow .h
#interface SonicUserTableRow : AWSDynamoDBModel <AWSDynamoDBModeling>
#property (nonatomic, strong) NSString *UserId;
#property (nonatomic, strong) NSString *Username;
#property (nonatomic, strong) NSString *profileImage;
#property (nonatomic, strong) NSString *active;
#property (nonatomic, strong) NSString *email;
#property (nonatomic, strong) NSString *flags;
#property (nonatomic, strong) NSString *attuned;
I have UserId value UserIdString: us-east-1:4ae0a93a-59a6-45fd-80c8-ff6b99f1d152 in the database so am trying to call for example: [self getTableRow:#"us-east-1:4ae0a93a-59a6-45fd-80c8-ff6b99f1d152"];
If DropId is a hash key of your table, you can use - load:hashKey:rangeKey: to load a single item.

Resources