@@ -62,14 +62,14 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
6262
6363 Initialize a MSALPublicClientApplication with a MSALPublicClientApplicationConfig.
6464 MSALPublicClientApplicationConfig can be initialized with client id, redirect uri and authority.
65- Redirect uri will be constucted automatically in the form of "msauth. <your-bundle -id-here>://auth" if not provided.
66- The scheme part, i.e. "msauth. <your-bundle -id-here>", needs to be registered in the info.plist of the project
65+ Redirect uri will be constucted automatically in the form of "msal <your-client -id-here>://auth" if not provided.
66+ The scheme part, i.e. "msal <your-client -id-here>", needs to be registered in the info.plist of the project
6767 */
6868
6969 let pcaConfig = MSALPublicClientApplicationConfig ( clientId: kClientID)
7070 self . application = try MSALPublicClientApplication ( configuration: pcaConfig)
7171 } catch {
72- self . loggingText . text = " Unable to create application \( error) "
72+ self . updateLoggingText ( text: " Unable to create application \( error) " )
7373 }
7474 }
7575
@@ -109,17 +109,17 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
109109 application. acquireToken ( with: parameters) { ( result, error) in
110110 if let result = result {
111111 self . accessToken = result. accessToken
112- self . loggingText . text = " Access token is \( self . accessToken ?? " Empty " ) "
112+ self . updateLoggingText ( text: " Access token is \( self . accessToken ?? " Empty " ) " )
113113 self . signoutButton. isEnabled = true
114114 self . callGraphApiButton. isEnabled = true
115115 self . editProfileButton. isEnabled = true
116116 self . refreshTokenButton. isEnabled = true
117117 } else {
118- self . loggingText . text = " Could not acquire token: \( error ?? " No error informarion " as! Error ) "
118+ self . updateLoggingText ( text: " Could not acquire token: \( error ?? " No error informarion " as! Error ) " )
119119 }
120120 }
121121 } catch {
122- self . loggingText . text = " Unable to create authority \( error) "
122+ self . updateLoggingText ( text: " Unable to create authority \( error) " )
123123 }
124124 }
125125
@@ -156,13 +156,13 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
156156
157157 application. acquireToken ( with: parameters) { ( result, error) in
158158 if let error = error {
159- self . loggingText . text = " Could not edit profile: \( error) "
159+ self . updateLoggingText ( text: " Could not edit profile: \( error) " )
160160 } else {
161- self . loggingText . text = " Successfully edited profile "
161+ self . updateLoggingText ( text: " Successfully edited profile " )
162162 }
163163 }
164164 } catch {
165- self . loggingText . text = " Unable to construct parameters before calling acquire token \( error) "
165+ self . updateLoggingText ( text: " Unable to construct parameters before calling acquire token \( error) " )
166166 }
167167 }
168168
@@ -195,7 +195,7 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
195195 */
196196
197197 guard let thisAccount = try self . getAccountByPolicy ( withAccounts: application. allAccounts ( ) , policy: kSignupOrSigninPolicy) else {
198- self . loggingText . text = " There is no account available! "
198+ self . updateLoggingText ( text: " There is no account available! " )
199199 return
200200 }
201201
@@ -223,38 +223,38 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
223223 self . application. acquireToken ( with: parameters) { ( result, error) in
224224 if let result = result {
225225 self . accessToken = result. accessToken
226- self . loggingText . text = " Access token is \( self . accessToken ?? " empty " ) "
226+ self . updateLoggingText ( text: " Access token is \( self . accessToken ?? " empty " ) " )
227227
228228 } else {
229- self . loggingText . text = " Could not acquire new token: \( error ?? " No error informarion " as! Error ) "
229+ self . updateLoggingText ( text: " Could not acquire new token: \( error ?? " No error informarion " as! Error ) " )
230230 }
231231 }
232232 return
233233 }
234234 }
235235
236- self . loggingText . text = " Could not acquire token: \( error) "
236+ self . updateLoggingText ( text: " Could not acquire token: \( error) " )
237237 return
238238 }
239239
240240 guard let result = result else {
241241
242- self . loggingText . text = " Could not acquire token: No result returned "
242+ self . updateLoggingText ( text: " Could not acquire token: No result returned " )
243243 return
244244 }
245245
246246 self . accessToken = result. accessToken
247- self . loggingText . text = " Refreshing token silently "
248- self . loggingText . text = " Refreshed access token is \( self . accessToken ?? " empty " ) "
247+ self . updateLoggingText ( text: " Refreshing token silently " )
248+ self . updateLoggingText ( text: " Refreshed access token is \( self . accessToken ?? " empty " ) " )
249249 }
250250 } catch {
251- self . loggingText . text = " Unable to construct parameters before calling acquire token \( error) "
251+ self . updateLoggingText ( text: " Unable to construct parameters before calling acquire token \( error) " )
252252 }
253253 }
254254
255255 @IBAction func callApi( _ sender: UIButton ) {
256256 guard let accessToken = self . accessToken else {
257- self . loggingText . text = " Operation failed because could not find an access token! "
257+ self . updateLoggingText ( text: " Operation failed because could not find an access token! " )
258258 return
259259 }
260260
@@ -266,18 +266,18 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
266266
267267 urlSession. dataTask ( with: request) { data, response, error in
268268 guard let validData = data else {
269- self . loggingText . text = " Could not call API: \( error ?? " No error informarion " as! Error ) "
269+ self . updateLoggingText ( text: " Could not call API: \( error ?? " No error informarion " as! Error ) " )
270270 return
271271 }
272272
273273 let result = try ? JSONSerialization . jsonObject ( with: validData, options: [ ] )
274274
275275 guard let validResult = result as? [ String : Any ] else {
276- self . loggingText . text = " Nothing returned from API "
276+ self . updateLoggingText ( text: " Nothing returned from API " )
277277 return
278278 }
279279
280- self . loggingText . text = " API response: \( validResult. debugDescription) "
280+ self . updateLoggingText ( text: " API response: \( validResult. debugDescription) " )
281281 } . resume ( )
282282 }
283283
@@ -294,7 +294,7 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
294294 if let accountToRemove = thisAccount {
295295 try application. remove ( accountToRemove)
296296 } else {
297- self . loggingText . text = " There is no account to signing out! "
297+ self . updateLoggingText ( text: " There is no account to signing out! " )
298298 }
299299
300300 self . signoutButton. isEnabled = false
@@ -303,7 +303,7 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
303303 self . refreshTokenButton. isEnabled = false
304304
305305 } catch {
306- self . loggingText . text = " Received error signing out: \( error) "
306+ self . updateLoggingText ( text: " Received error signing out: \( error) " )
307307 }
308308 }
309309
@@ -354,5 +354,11 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
354354 }
355355 return try MSALB2CAuthority ( url: authorityURL)
356356 }
357+
358+ func updateLoggingText( text: String ) {
359+ DispatchQueue . main. async {
360+ self . loggingText. text = text
361+ }
362+ }
357363}
358364
0 commit comments