on master help sign in
Added vk support
a0a6486ilyakooo0
Melk/AppDelegate.swift+9
@@ -7,6 +7,7 @@
7//
7//
8
8
9import UIKit
9import UIKit
10+import SwiftyVK
10
11
11@UIApplicationMain
12@UIApplicationMain
12class AppDelegate: UIResponder, UIApplicationDelegate {
13class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -22,6 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
22 mainWindow.screen = UIScreen.main
23 mainWindow.screen = UIScreen.main
23 mainWindow.makeKeyAndVisible()
24 mainWindow.makeKeyAndVisible()
24 coordinator = MainCoordinator(window: mainWindow)
25 coordinator = MainCoordinator(window: mainWindow)
26+ coordinator.start()
25
27
26 NotificationCenter.default.addObserver(forName: NSNotification.Name.UIScreenDidConnect, object: nil, queue: OperationQueue.main) { (_) in
28 NotificationCenter.default.addObserver(forName: NSNotification.Name.UIScreenDidConnect, object: nil, queue: OperationQueue.main) { (_) in
27 self.updateScreens()
29 self.updateScreens()
@@ -34,6 +36,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
34 // Override point for customization after application launch.
36 // Override point for customization after application launch.
35 return true
37 return true
36 }
38 }
39+
40+ func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
41+ let app = options[.sourceApplication] as? String
42+ VK.process(url: url, sourceApplication: app)
43+ return true
44+ }
45+
37
46
38 func applicationWillResignActive(_ application: UIApplication) {
47 func applicationWillResignActive(_ application: UIApplication) {
39 // 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.
48 // 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.
Melk/Info.plist+18
@@ -16,8 +16,26 @@
16 <string>APPL</string>
16 <string>APPL</string>
17 <key>CFBundleShortVersionString</key>
17 <key>CFBundleShortVersionString</key>
18 <string>1.0</string>
18 <string>1.0</string>
19+ <key>CFBundleURLTypes</key>
20+ <array>
21+ <dict>
22+ <key>CFBundleTypeRole</key>
23+ <string>Editor</string>
24+ <key>CFBundleURLName</key>
25+ <string>com.ilyakooo0.Melk</string>
26+ <key>CFBundleURLSchemes</key>
27+ <array>
28+ <string>vk6097091</string>
29+ </array>
30+ </dict>
31+ </array>
19 <key>CFBundleVersion</key>
32 <key>CFBundleVersion</key>
20 <string>1</string>
33 <string>1</string>
34+ <key>LSApplicationQueriesSchemes</key>
35+ <array>
36+ <string>vkauthorize</string>
37+ <string>vk6097091</string>
38+ </array>
21 <key>LSRequiresIPhoneOS</key>
39 <key>LSRequiresIPhoneOS</key>
22 <true/>
40 <true/>
23 <key>UILaunchStoryboardName</key>
41 <key>UILaunchStoryboardName</key>
Melk/MainCoordinator.swift+70−1
@@ -7,20 +7,89 @@
7//
7//
8
8
9import UIKit
9import UIKit
10+import SwiftyVK
10
11
11class MainCoordinator {
12class MainCoordinator {
12 let window: UIWindow
13 let window: UIWindow
13 let mainVC = MainViewController()
14 let mainVC = MainViewController()
15+ let loadingVC = UIViewController() // TODO: An actual loading VC
14 let navC: UINavigationController!
16 let navC: UINavigationController!
15 let secondaryCoord = SecondaryCoordinator()
17 let secondaryCoord = SecondaryCoordinator()
16 init(window: UIWindow) {
18 init(window: UIWindow) {
17 self.window = window
19 self.window = window
20+ window.rootViewController = loadingVC
21+
22+
18 navC = UINavigationController(rootViewController: mainVC)
23 navC = UINavigationController(rootViewController: mainVC)
19− window.rootViewController = navC
20 updateScreens()
24 updateScreens()
25+
26+ }
27+
28+ func start() {
29+ VK.configure(withAppId: appID, delegate: self)
30+ if VK.state == .authorized {
31+ authorized()
32+ } else {
33+ VK.logIn()
34+ }
21 }
35 }
22
36
23 func updateScreens() {
37 func updateScreens() {
24 secondaryCoord.updateScreens()
38 secondaryCoord.updateScreens()
25 }
39 }
40+
41+ fileprivate func authorized() {
42+ print("didAuthorize")
43+ window.rootViewController = navC
44+ }
45+}
46+
47+extension MainCoordinator: VKDelegate {
48+ /** ---DEPRECATED. TOKEN NOW STORED IN KEYCHAIN--- Called when SwiftyVK need know where a token is located
49+ - returns: Path to save/read token or nil if should save token to UserDefaults*/
50+ func vkShouldUseTokenPath() -> String? {
51+ return nil
52+ }
53+
54+ func vkWillAuthorize() -> Set<VK.Scope> {
55+ //Called when SwiftyVK need authorization permissions.
56+ return permissions
57+ }
58+
59+ func vkDidAuthorizeWith(parameters: Dictionary<String, String>) {
60+ //Called when the user is log in.
61+ //Here you can start to send requests to the API.
62+ print("authorized")
63+ mainSync {
64+ self.window.rootViewController = self.navC
65+ }
66+ authorized()
67+ }
68+
69+ func vkAutorizationFailedWith(error: AuthError) {
70+ //Called when SwiftyVK could not authorize. To let the application know that something went wrong.
71+ print("failed auth with error \(error.errorCode): \(error.description)")
72+ mainSync {
73+ self.window.rootViewController = self.navC
74+ }
75+ }
76+
77+ func vkDidUnauthorize() {
78+ print("did unauthorize")
79+ mainSync {
80+ self.window.rootViewController = self.navC
81+ }
82+ //Called when user is log out.
83+ }
84+
85+ func vkWillPresentView() -> UIViewController {
86+ //Only for iOS!
87+ //Called when need to display a view from SwiftyVK.
88+ let authController = UIViewController()
89+ mainSync {
90+ self.window.rootViewController = authController
91+ }
92+ return authController //UIViewController that should present authorization view controller
93+ }
94+
26}
95}
Melk/PublicCrap.swift+10
@@ -247,3 +247,13 @@ struct DecayingAverage {
247 value = (value * weight + num) / (weight + 1)
247 value = (value * weight + num) / (weight + 1)
248 }
248 }
249}
249}
250+
251+func mainSync(_ code: (() -> ())) {
252+ if Thread.isMainThread {
253+ code()
254+ } else {
255+ DispatchQueue.main.sync {
256+ code()
257+ }
258+ }
259+}
Melk/VKPublicCrap.swift+18−18
@@ -9,29 +9,29 @@
9import SwiftyVK
9import SwiftyVK
10
10
11let permissions: Set<VK.Scope> = [
11let permissions: Set<VK.Scope> = [
12− .notify,
12+// .notify,
13− .friends,
13+// .friends,
14− .photos,
14+// .photos,
15− .audio,
15+// .audio,
16− .video,
16+// .video,
17− .docs,
17+// .docs,
18− .notes,
18+// .notes,
19 .pages,
19 .pages,
20− .status,
20+// .status,
21− .offers,
21+// .offers,
22− .questions,
22+// .questions,
23 .wall,
23 .wall,
24 .groups,
24 .groups,
25− .messages,
25+// .messages,
26− .email,
26+// .email,
27− .notifications,
27+// .notifications,
28− .stats,
28+// .stats,
29− .ads,
29+// .ads,
30− .offline,
30+// .offline,
31− .market
31+// .market,
32]
32]
33let vkAPIVersion = "5.60"
33let vkAPIVersion = "5.60"
34−let appID = "5529752"
34+let appID = "6097091"
35
35
36let multichatchatId = 2000000000
36let multichatchatId = 2000000000
37
37