I want to make an app in iphone such that it displays the history of safari browser in iphone. Means I want to access safari cookies through other app. This is the first time m placing a query on overflow...... can anybody please let me know about this... please do reply
i don't know whether it will work or not but you can try this using NSHTTPCookie and NSHTTPCookieStorage classes...
code would be similar this
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSURL *URL;
NSArray *cookies;
NSString *cookieString = #"";
cookies = [cookieStorage cookies];
if([cookies count] > 0) {
NSHTTPCookie *cookie =[cookies objectAtIndex:0];
cookieString = [NSString stringWithFormat: #"%#=%#", [cookie name], [cookie value]];
NSLog(cookieString);
}
Related
I want to set session and store values like cookies in the web browser in iPhone App. Is it possible? How can I implement this in iPhone? Can any one suggest a good solution..
Just set cookies like
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSHTTPCookie* testCookie = [NSHTTPCookie cookieWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
#"1", NSHTTPCookieValue,
#"test_cookie", NSHTTPCookieName,
#".facebook.com", NSHTTPCookieDomain,
#"/", NSHTTPCookiePath,
nil]];
[cookies setCookie:testCookie];
And Get the cookies like
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
//here you can get you specific cookies
}
My iOs app authenticates user with Facebook using facebook-sdk.
Now application connects to server and has to confirm that the user identity. Which is recommended way?
Probably iphone has to send some kind of token to server and server has to confirm it with facebook api call
do you have link to these docs?
hello u want to login with Facebook in your ios Application i have use this code for it pls check it
first take web view in you r Application and do connection with Nib file .and enter your facebook Appl
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *client_id = #"Enter your Application ";
NSString *redirect_uri = #"http://www.facebook.com/connect/login_success.html";
NSString *url_string = [NSString stringWithFormat:#"https://graph.facebook.com/oauth/authorize?client_id=%#&redirect_uri=%#&type=user_agent&display=touch", client_id, redirect_uri];
NSURL *url = [NSURL URLWithString:url_string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}
-(IBAction)getText:(id)sender{
NSLog(#"%#",[webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.outerHTML"]);
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
NSString *url_string = [((_webView.request).URL) absoluteString];
NSLog(#"%#",url_string);
NSRange access_token_range = [url_string rangeOfString:#"access_token="];
//coolio, we have a token, now let's parse it out....
if (access_token_range.length > 0) {
int from_index = access_token_range.location + access_token_range.length;
NSString *access_token = [url_string substringFromIndex:from_index];
NSLog(#"access_token: %#", access_token);
htmldata=[webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.outerHTML"];
NSLog(#"%#",htmldata);
NSLog(#"%#",url_string);
NSArray *arr1=[htmldata componentsSeparatedByString:#"<title>"];
NSString *data=[arr1 objectAtIndex:1];
NSArray *arr2=[data componentsSeparatedByString:#"</title>"];
value=[[NSString alloc]initWithString:[arr2 objectAtIndex:0]];
NSLog(#"%#",value);
if([value isEqualToString:#"Success"])
{
MainScreenController *C = [[MainScreenController alloc]init];
[self.navigationController pushViewController:C animated:YES];
[C release];
}
}
}
thanks
In my iPhone application I want to clear the cache and cookies at the logout page. Please give proper suggestions for that. Now I am using the below code, but it is not working properly.
[[NSURLCache sharedURLCache] removeAllCachedResponses];
I've been able to make it work using NSHTTPCookie and NSHTTPCookieStorage
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"facebook"]; //i used this to remove facebook related cookie so gave the domain name as facebook
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
I've never actually worked with clearing cache, but used a piece of code which disables caching
NSURLCache *disableCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:disableCache];
[disableCache release];
Facebook is not integrating with my application. even the sample codes are not working
Is facebook having some problem with iOS because the documentation and sample codes on developer.facebook also not found.
use this sharekit
it can integrate facebook, twitter, and much more apis
Try this new facebook grpah api
code for login on any button
fbGraph.accessToken = nil;
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"facebook"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
[self loginButtonPressed:nil];
here is my code:
-(IBAction)itunesBuy:(id)sender{
// NSString *urlString = [[NSString alloc] initWithFormat:#"http://itunes.com/%#/%#", self.artistTerm,self.titleTerm];
NSString *urlString = [[NSString alloc] initWithFormat:#"http://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?albumTerm=%#", self.titleTerm];
NSLog(#"urlString=%#", urlString);
NSString *escapedValue = [(NSString *)CFURLCreateStringByAddingPercentEscapes(nil,(CFStringRef)urlString,NULL,NULL,kCFStringEncodingUTF8) autorelease];
NSURL *itunesUrl = [NSURL URLWithString:escapedValue];
if (![[UIApplication sharedApplication] openURL:itunesUrl])
NSLog(#"%#%#",#"Failed to open url:",[itunesUrl description]);
}
You can see that I tried the simpler itunes link as well. My understanding was that this won't work on the simulator, but should on the device.
On my iPad and my iPhone, it launches itunes, but then I get an error saying:"Your request could not be completed. This search cannot be performed on this device."
Any help would be appreciated.
Steve
There is no advanced search in device appstore, only in itunes on your Mac/PC.
Try to use the simple search with "itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?term=%#".