T
T
tupoi2018-04-06 23:31:48
iOS
tupoi, 2018-04-06 23:31:48

How to get token from url?

Good day, please tell me how to get the access_token from the url intercepted in the webView?
The url looks like this

https://oauth.vk.com/blank.html#access_token=111111111&expires_in=86400&user_id=1111111

I'm just wondering if there is any ready-made swift method for such a case, or do I need to do it manually?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Grib, 2018-04-06
@YeahGarage

Write match method
func canOpenURL(string: String?) -> Bool {
guard let urlString = string else {return false}
guard let url = NSURL(string: urlString) else {return false}
let regEx = "_________________________"
let predicate = NSPredicate (format:"SELF MATCHES %@", argumentArray:[regEx])
return predicate.evaluate(with: string)
}

A
Aleksandr Govorukhin, 2018-04-26
@SnapSh0t

There is a simpler, ready-made solution. Or no one canceled regular expressions ;)

if (result.token) { 
// Пользователь успешно авторизован 
} else if (result.error) { 
// Пользователь отменил авторизацию или произошла ошибка 
}

iOS SDK

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question