Facebook: obtain album id just created with Photos.createAlbum - iphone

I'm developing an iPhone app that creates a Photo Album to hold the pictures that the user is going to upload.
On - (void)request:(FBRequest*)request didLoad:(id)result { I'm trying to obtain the aid returned with this code:
else if ([#"Photos.createAlbum" isEqualToString: request.method]) {
NSLog(#"[Photos.createAlbum:dialogDidSucceed] succeed");
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *aid = [[NSString alloc] initWithString: [request.params objectForKey:#"aid"]];
[prefs setObject:aid forKey:_ALBUMID];
[prefs synchronize];
//[prefs release];
[aid release];
if (pendingUploadImage) {
[self btnUploadImage];
}
}
Here said that the aid is returned, but I don't know where.
How can I obtain album id?

If anywhere, it must be in result, which is a dictionary containing the response data from the web service. It certainly cannot be part of the request (where your code assumes it is).

Related

How to download xml file and save in local iphone application

I have a magazine application i want that it load file from server and store it in application when application starts first time only and then use that locally file to save time i am getting data which is located on server it takes alot time
NSURL*myurl=url;
myurl = [myurl stringByReplacingOccurrencesOfString:#"\n" withString:#""];
myurl = [myurl stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL*urlloaded= [[NSURL alloc]initWithString:myurl];
//NSURL*url= [[NSURL alloc]initWithString:#"http://localhost:8888/RowOne.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:urlloaded];
//Initialize the delegate.
RowTwoParser *parser = [[RowTwoParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
BOOL success = [xmlParser parse];
if(success)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
What you can do is:-
Suppose you have parsed your xml and stored data in array say 'dataArray'
Now you have to save your dataArray in NSUserDefaults
NSUserDefaults *pref1=[NSUserDefaults standardUserDefaults];
[pref1 setObject:dataArray forKey:#"parseData"];
[pref1 synchronize];
Whenever you have to use this data you can extract it like:-
NSUserDefaults *pref1=[NSUserDefaults standardUserDefaults];
NSArray *dataArray=[pref1 objectForKey:#"parseData"];
You can download the initial data i.e the XML file by using something like this
- (void)downloadInitialData {
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
if ([userDefaults boolForKey:#"DATA_DOWNLOAD_KEY"] == NO) {
[self showWaitViewWithText:#"Downloading Data..."];
[self fetchDataFromServer];
}
}
- (void)fetchDataFromServer {
//Call to server to downlaod data
//When Data is successfully downloaded
//Stop loading when data save completes
[self stopLoading];
//Update USerDefaults
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:YES forKey:#"DATA_DOWNLOAD_KEY"];
[userDefaults synchronize];
}
You can make call to [self downloadInitialData]; which will ensure that Data is downloaded only once when the application starts . You will have to fix it according to your requirements to download data by resetting the #"DATA_DOWNLOAD_KEY" key.
Check out Apples own SeismicXML example - source code available.

Way to persist MPMediaItemCollection objects? (selected from iPod)

I am making an app in which the user can select a song in a settings tab and have this played in a different view on demand. I want it so that this item can be stored if the user is to shut the app and reopen it another time.
I have managed to allow the user to select and store a song in with:
-(IBAction)showMediaPicker:(id)sender{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.prompt = #"Select Alarm Sound";
[self presentModalViewController:mediaPicker animated:YES];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {
[self dismissModalViewControllerAnimated: YES];
settingsData.selectedSong = mediaItemCollection;//Object of type MPMediaItemCollection
but I want the user to have to do this every time they use the app.
I have tried using NSUserDefaults:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:settingsData.selectedSong forKey:#"alarmSoundKey"];
[defaults synchronize];
but get the error:
* -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '' of class 'MPMediaItemCollection'. Note that dictionaries and arrays in property lists must also contain only property values.
What are my options please? Not really sure how to tackle this one...
SOLUTION -
I can't answer my own questions yet so I'll put it up here:
I HAVE FOUND MY OWN SOLUTION TO THIS:
First convert/encode the MPMediaItemCollection to an NSData Object and slam store it using NSUserDefaults using:
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:mediaItemCollection];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:data forKey:#"someKey"];
[defaults synchronize];
From there, you can decode and use anywhere else in your app....
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *data = [defaults objectForKey:#"someKey"];
MPMediaItemCollection *mediaItemCollection = [NSKeyedUnarchiver unarchiveObjectWithData:data]
Hope that is some help to someone. Spread the word, this hasn't been covered enough. Have literally been working on this problem for about 4 hours...
You can only store property list values in NSUserDefaults. Since MPMediaItemCollection conforms to NSCoding you could use an NSKeyedArchiver to store it instead.
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSKeyedArchiver_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40003672
You then use NSKeyedUnarchiver to read it back out of the file later.
You can also use the MPMediaItemPropertyPersistentID property. You can form a query to retrieve the item from the iPod library when your application next launches, and gracefully handle things like when the user decides to remove the song from their library.

How to keep given password in mgtwitterengine api

I want to keep password which is given by user in a variable. Where to get password value. I look in code but it is containing only username. I am using MGTwitterengine api in my application. Here is the function which is printing data on console.
-(void)setUsername:(NSString *)newUsername password:(NSString *)newPassword
{
NSLog(#"uset sername %# and password %#",newUsername,newPassword);
...
}
I debug in all function but I saw this function is running after loggedin. But this is printing null in password value although username is printing well. Actually I I have to trace all tweet value of user. I went through MGTwitterEngine. There is a block of code but it is necessary to write username and password.
Here is the code
MGTwitterEngine *twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:#"username" password:#"password"];
// Get updates from people the authenticated user follows.
NSString *connectionID = [twitterEngine getFollowedTimelineFor:nil since:nil startingAtPage:0];
Please help me how to keep password ?
Read the developer documentation, it provides all the info you need for something as easy as this. Back to the question, there're a couple of ways how you can save this data.
NSUserDefaults: You can save the username and password using this class like this:
[[NSUserDefaults sharedUserDefaults] setObject:username forKey:#"username"];
[[NSUserDefaults sharedUserDefaults] setObject:username forKey:#"password"];
[[NSUserDefaults sharedUserDefaults] synchronize];
Once you need this data again, call it:
NSString*username = [[NSUserDefaults standardUserDefaults] objectForKey:#"username"];
NSString*password = [[NSUserDefaults standardUserDefaults] objectForKey:#"password"];
OR:
NSDictionary: If you don't want to rely on NSUserDefaults, you can save the login data in a NSDictionary and save it to your sandbox. This works like this:
NSMutableDictionary*loginDictionary = [[NSMutableDictionary alloc] init];
[loginDictionary setObject:username forKey:#"username"];
[loginDictionary setObject:password forKey:#"password"];
[loginDictionary writeToFile://Your Path Here atomically:NO];
[loginDictionary release];
Then, once you need the data again, read from file:
NSMutableDictionary*loginDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile://Your Path];
NSString*username = [loginDictionary objectForKey:#"username"];
NSString*password = [loginDictionary objectForKey:#"password"];
[loginDictionary release];
Hope it helps!

Saving Facebook access_token in NSUserDefaults on iOS

iOS beginner here. I'm using the following code to save my facebook accessToken and expirationDate in NSUserDefaults:
facebook = [[Facebook alloc] initWithAppId:#"225083222506272"];
[facebook authorize:nil delegate:self];
NSString *access=[facebook accessToken];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:access, #"accessToken",[facebook expirationDate], #"expirationDate",nil];
[defaults registerDefaults:appDefaults];
And I'm trying to retrieve accessToken and expirationDate in a later call with:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *access=[defaults valueForKey:#"accessToken"];
NSDate *date=[defaults objectForKey:#"expirationDate"];
[facebook fbDialogLogin:access expirationDate:date];
but access and date are null. What am I doing wrong?
The code here is not synchronous. It means it does not block after the call to [facebook authorize:nil delegate:self];. You should instead implement the fbDidLogin delegate method to be notified of when the user has actually logged in successfully. At that point, retrieve the access tokens and save them to user defaults.
Here's a partial sample:
- (void)userClickedFacebookLogin {
[facebook authorize:nil delegate:self]; // delegate is self
}
// Delegate method that you should implement to get notified
// when user actualy logs in.
- (void)fbDidLogin {
// now get the access token and save to user defaults
NSString *access = [facebook accessToken];
// ..
}
Also make sure that the class which has the above code implements the FBSessionDelegate protocol at minimum.
#interface MyClass <FBSessionDelegate> {
}
#end
Look at the DemoApp sample and specifically the DemoAppViewController class from Facebook to get a better idea.

Can I change the apps view based on if a file has been saved?

Please help! I'm a newbie to programming and I'm having the following trouble. I am trying to write my first iphone app and I would like it to do the following.
When the app launches user enters name, presses button and goes to new view. Their name is saved to file and used through out the app. That much I have managed.
I would like the app to check to see if there is a saved file when it is launched and go directly to second view instead of the first view. I'm have search for days looking for an answer and I'm still not sure how to do this.
At the risk of seeming stupid do I use an IF statement and how do I write it. Please help.
Thanking you in advance.
You have to use NSUserDefaults for storing the user name and pass words. If you want to store more data's, have to use plist(Documents Directory) or core data or SQLite.
// Store the data
[[NSUserDefaults standardUserDefaults] setObject:#"yourPasswordString" forKey:#"YourKey"];
// Retrieve the data
NSString *passWord = [[NSUserDefaults standardUserDefaults] objectForKey:#"YourKey"];
Once you retrieved the data, you have to check the conditions like,
if(passWord == nil)
{
//load first view
}
else
{
// load second view
}
Thanks!
if you're using NSUserDefaults to save it then all you have to do is try reading the value into a string, then check if it is nil, if it is, then the files isn't there and you would load your first view, if it was, then load your second view.
NSString *tempStr = [[NSUserDefaults standardUserDefaults] objectForKey:#"yourKey"];
if(tempStr == nil)
{
//load your first view
}
else
{
// load your second view
}
You need to read your key back out in order to test if it is nil, the way you are doing this, you will never be nil and will always use the else choice, you need to set your object elsewhere, probably in the if statement.
-(IBAction)LogInButton:(id)sender
{
NSString *tempStr = [[NSUserDefaults standardUserDefaults] objectForKey:#"UserName"];
if (tempStr == nil || [tempStr isEqualToString:""])
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:Name.text forKey:#"UserName"];
[prefs synchronize];
ClubSearchViewController *CSearch = [[ClubSearchViewController alloc]initWithNibName:#"ClubSearchViewController" bundle:Nil];
[self presentModalViewController:CSearch animated:YES];
}
else
{
SearchMenu *SMenu = [[SearchMenu alloc]initWithNibName:#"SearchMenu" bundle:nil];
[self presentModalViewController:SMenu animated:YES];
}
}
-(IBAction)LogOutButton:(id)sender
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:#"" forKey:#"UserName"];
[prefs synchronize];
}