@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時,它會顯示白色屏幕。請幫助我進入這個,我是新的迅速:) –