2

Пытаюсь настроить VK iOS SDK (проект для себя) в проекте на Swift (Xcode 7) - и никак. Не могу понять в чем ошибка.

AppDelegate.swift:

//
//  AppDelegate.swift
//  iosVKMusic
//
//  Created by Nick on 25.06.15.
//  Copyright © 2015 Funtrum. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
        let ret:Bool = VKSdk.processOpenURL(url, fromApplication: sourceApplication)
        return ret
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
}

ViewController.swift:

//
//  ViewController.swift
//  iosVKMusic
//
//  Created by Nick on 25.06.15.
//  Copyright © 2015 Funtrum. All rights reserved.
//

import UIKit

extension ViewController: VKSdkDelegate {
    func vkSdkNeedCaptchaEnter(captchaError: VKError) { }
    func vkSdkTokenHasExpired(expiredToken: VKAccessToken) { }
    func vkSdkUserDeniedAccess(authorizationError: VKError) { }
    func vkSdkShouldPresentViewController(controller: UIViewController) { }
    func vkSdkReceivedNewToken(newToken: VKAccessToken) { }
}

class ViewController: UIViewController {

    let TOKEN_KEY = "my_application_access_token"

    override func viewDidLoad() {
        super.viewDidLoad()
        VKSdk.initializeWithDelegate(self, andAppId: "4314639")

        /*
        let audioReq: VKRequest = VKRequest(method: "audios.get", andParameters: [VK_API_OWNER_ID : "0"], andHttpMethod: "GET")
        audioReq.executeWithResultBlock(
            {
                (response) -> Void in

                let audios =  response.json as! NSArray
                print(audios, appendNewline: true)
                if let count: AnyObject = audios[0].objectForKey("count") {
                    print(count, appendNewline: true)
                }

            }, errorBlock: {
                (error) -> Void in
                print("error", appendNewline: true)
                NSLog("VK error: %@", error)

        })
        */
    }
    @IBAction func authTouchUp(sender: UIButton) {
        if (VKSdk.wakeUpSession()) {
            print("wakeUpSession", appendNewline: true)
        } else {
            print("else", appendNewline: true)
            VKSdk.authorize([VK_PER_AUDIO, VK_PER_OFFLINE], revokeAccess: true)
        }
    }

    func vkSdkAcceptedUserToken(token: VKAccessToken!) {
        print("ACCEPTED", appendNewline: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Bridgind Header.h:

//
//  -Bridging-Header.h
//  iosVKMusic
//
//  Created by Nick on 28.06.15.
//  Copyright © 2015 Funtrum. All rights reserved.
//

#ifndef _Bridging_Header_h
#define _Bridging_Header_h


#endif /* _Bridging_Header_h */

#import "VKSdk.h"

При авторизации (VKSdk.autorize(...)) выдает ошибку:

2015-06-29 16:11:14.931 iosVKMusic[554:75899] -canOpenURL: failed for URL: "vkauthorize://authorize" - error: "This app is not allowed to query for scheme vkauthorize"

В чем может быть дело?

2
  • Спасибо за редактирование, только осваиваюсь, @Regent
    – nickaroot
    29 июн 2015 в 14:49
  • На здоровье. Весьма надеюсь, что в следующий раз вы сами код в вопрос вставите, потому что я немало времени потратил на его вставку в вопрос :)
    – Regent
    29 июн 2015 в 14:52

1 ответ 1

2

Проблема была решена добавлением строк в Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>vkauthorize</string>
</array>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.