2015-08-18 111 views
0

我試圖在從圖形api鏈接中檢索後,將facebook用戶的圖像存儲在NSUserDefault中。 這是我要送鏈接:如何存儲從Facebook圖形檢索圖像到NSUserDefaults

NSString *fbuid = [NSString stringWithFormat:@"%@",[result objectForKey:@"id"]]; 

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", fbuid]]; 

,然後用這個網址我這樣做:

NSData *data = [NSData dataWithContentsOfURL:url]; 
NSString *stringImage = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; 

的將其存儲在用戶的默認值:

[[NSUserDefaults standardUserDefaults]setObject:url forKey:@"dp"]; 

回答

0

在這裏你可以用多種方式使用這個概念。例如

一個

只是保存在idNSUserDefaults,你需要訪問這就像

NSString *fbuid = [NSString stringWithFormat:@"%@",[result objectForKey:@"id"]]; 
[[NSUserDefaults standardUserDefaults]setObject: fbuid forKey:@"dp"]; 
[[NSUserDefaults standardUserDefaults]synchronize]; 

檢索

//這裏在使用圖像顯示一樣這

UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", [[NSUserDefaults standardUserDefaults]objectForKey:@"dp"]]]]; 

兩個URL字符串保存到NSUserDefaults,就像

NSString *fbuid = [NSString stringWithFormat:@"%@",[result objectForKey:@"id"]]; 
    NSString *URLStr=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", fbuid]]; 

[[NSUserDefaults standardUserDefaults]setObject: URLStr forKey:@"dp"]; 
[[NSUserDefaults standardUserDefaults]synchronize]; 

檢索

UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", [[NSUserDefaults standardUserDefaults]objectForKey:@"dp"]]]]; 
+0

我只是說'[[NSUserDefaults的standardUserDefaults]的setObject:[的NSString stringWithFormat:@「% @「,url] forKey:@」dp「];'它的工作原理是:D –

+0

urs希望,我們可以通過多種方式實施,偉大的一天 –

相關問題