@Satyam
能否请您分享您的代码,这样我就可以得到更好的主意。
在这里你去: 代码是迅速,但你可以很容易地转换成Objective C的
作用域: offline_access,onedrive.readonly,onedrive.readwrite,onedrive.appfolder把按您的要求( https://dev.onedrive.com/auth/msa_oauth.htm#authentication-scopes)
夫特:
let kMicrosoftApplicationId = "<MicrosoftApplicationId>"
let kMicrosoftRedirectURL = "urn:ietf:wg:oauth:2.0:oob"
let scopesMicroSoft = ["onedrive.readwrite","onedrive.appfolder"]
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//ONE DRIVE
ODClient.setMicrosoftAccountAppId(kMicrosoftApplicationId, scopes: scopesMicroSoft)
return true
}
的ViewController希望在何处登录:
您必须声明ODClient的对象顶部
import OneDriveSDK
var odClient: ODClient!
func oneDriveClick(sender: UIButton){
authenticateUser()
}
func authenticateUser(){
ODClient.clientWithCompletion { (client, error) in
if ((error == nil)){
self.odClient = client
ODClient.setCurrentClient(client)
self.getUserDetails()
}else{
print("Login error :::: \(error)")
}
}
}
func getUserDetails(){
odClient.drive().request().getWithCompletion { (drive, error) -> Void in
if(error == nil){
print("User name : \(drive.owner.user.displayName)")
}
}
}
目标C:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[ODClient setMicrosoftAccountAppId: kMicrosoftApplicationId scopes:@[@"onedrive.readwrite",@"onedrive.appfolder"] ];
return YES;
}
的ViewController希望在何处登录:
.H代码
@property (strong, nonatomic) ODClient *odClient;
。M档代码
- (void)oneDriveClick
{
[self authenticateUser];
}
- (void)authenticateUser{
[ODClient authenticatedClientWithCompletion:^(ODClient *client, NSError *error){
if (!error){
self.odClient = client;
[ODClient setCurrentClient:client];
[self getUserDetails];
}
else{
NSLog(@"Error Login :%@",error);
}
}];
}
- (void)getUserDetails{
[[[self.odClient drive] request] getWithCompletion:^(ODDrive *drive, NSError *error){
if (!error){
NSLog(@"User name : %@",drive.owner.user.displayName);
}
}];
}
享受:)(Y)
你有足够的代表处,现在要发表评论,请不要使用应答节本。谢谢。 –
@dan对不起,谢谢你的建议:) – iPhoneDev
@iPhoneDev感谢您的回复,我在Swift上试过了您的代码,但是我收到了错误。我们需要在启动时声明odClient,但我不知道它是哪种类型的odClient,也是在getUserDetails方法中odClient给我使用未解析标识符'odClient'的错误。 &在应用程序委托方法它将是返回类型,但是当我返回true时,它会显示白色屏幕。请帮助我进入这个,我是新的迅速:) –