Yandex.Disk 俄罗斯网盘,俄罗斯第一网盘。
打开网页之后,看了第一眼,全是俄语……
嗯,很好,关闭网页,收拾行李,江湖路远,我们有缘再见!!
开个玩笑,开个玩笑,贫穷限制了我的行动力。
我热爱学习,热爱工作!
打开网页,只能硬着头皮上了。翻了半天,没有pod导入?嗯?要不放弃?
开什么玩笑,我那么
热爱工作!
好在在官方网站上还是找到了他们的代码,只可惜需要自己手动去导入。而且直接下载的话,KissXML并不会被下载下来,还需要跑去专门把它给下载下来。
导入头文件
// Yandex.disk
#import "YDSession.h"
#import "YOAuth2Delegate.h"
#import "YOAuth2ViewController.h"
开始
- (void)yandexAction {
[self yandexAuthor];
}
授权
- (void)yandexAuthor {
if (self.ydSession == nil) {
self.ydSession = [[YDSession alloc] initWithDelegate:self];
}
// 如果没有认证
if (!self.ydSession.authenticated) {
YOAuth2ViewController *vc = [[YOAuth2ViewController alloc] initWithDelegate:self];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.ydLoginVc = nav;
[self presentViewController:nav animated:YES completion:nil];
}else {
[self yandexUploadFile:[[NSBundle mainBundle] pathForResource:@"4.pdf" ofType:nil]];
}
}
上传
// 上传
- (void)yandexUploadFile:(NSString *)filePath {
[self.ydSession uploadFile:filePath toPath:[NSString stringWithFormat:@"/%@",filePath.lastPathComponent] completion:^(NSError *err) {
NSLog(@"err");
}];
[self.ydSession fetchDirectoryContentsAtPath:@"/" completion:^(NSError *err, NSArray *list) {
NSLog(@"%@",list);
}];
}
YDSessionDelegate
-(NSString *)userAgent
{
return @"A1B2C3D4E6.com.face.magic";
}
YOAuth2Delegate
#pragma mark YOAuth2Delegate
- (NSString *)clientID
{
return @"24aa9da88a8a4b93b4a991f544cdd4cf";
}
-(NSString *)redirectURL
{
//#warning Replace the following with the data you got when registering your app at: https://oauth.yandex.ru/
return @"https://yx24aa9da88a8a4b93b4a991f544cdd4cf.oauth.yandex.ru/auth/finish?platform=ios";
}
- (void)OAuthLoginSucceededWithToken:(NSString *)token
{
self.ydSession.OAuthToken = token;
[self.ydLoginVc dismissViewControllerAnimated:YES completion:^{
[self yandexUploadFile:[[NSBundle mainBundle] pathForResource:@"4.pdf" ofType:nil]];
}];
}
- (void)OAuthLoginFailedWithError:(NSError *)error
{
NSLog(@"It's time to PANIC: %@", error);
[self.ydLoginVc dismissViewControllerAnimated:YES completion:nil];
}
OK,结束。
帮助文档:
不存在的。
网友评论