Skip to content

Commit 2554915

Browse files
committed
Use ASWebAuthenticationSession instead of SFAuthenticationSession (iOS >= 12)
1 parent c6dac56 commit 2554915

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
</a>
2323
</p>
2424

25-
<p align="center">
26-
<h1 align="center">InAppBrowser for NativeScript</h1>
27-
</p>
25+
<h1 align="center">InAppBrowser for NativeScript</h1>
26+
<h4 align="center"><a href="https://developer.chrome.com/multidevice/android/customtabs#whatarethey">Chrome Custom Tabs</a> for Android & <a href="https://developer.apple.com/documentation/safariservices">SafariServices</a>/<a href="https://developer.apple.com/documentation/authenticationservices">AuthenticationServices</a> for iOS.</h4>
2827

2928
<p align="center">
3029
<img width="400px" src="img/inappbrowser.png">
@@ -42,7 +41,7 @@ Methods | Action
4241
------------- | ------
4342
`open` | Opens the url with Safari in a modal on iOS using **SFSafariViewController**, and Chrome in a new custom tab on Android. On iOS, the modal Safari will not share cookies with the system Safari.
4443
`close` | Dismisses the system's presented web browser
45-
`openAuth` | Opens the url with Safari in a modal on iOS using **SFAuthenticationSession**, and Chrome in a new custom tab on Android. On iOS, the user will be asked whether to allow the app to authenticate using the given url.
44+
`openAuth` | Opens the url with Safari in a modal on iOS using **SFAuthenticationSession/ASWebAuthenticationSession**, and Chrome in a new custom tab on Android. On iOS, the user will be asked whether to allow the app to authenticate using the given url.
4645
`closeAuth` | Dismisses the current authentication session
4746
`isAvailable` | Detect if the device supports this plugin
4847

demo/app/tests/tests.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1+
var application = require('tns-core-modules/application')
2+
var utils = require('tns-core-modules/utils/utils')
13
var InAppBrowser = require('nativescript-inappbrowser').default
24

3-
describe("open function", function () {
4-
it("exist", function () {
5+
describe("isAvailable", function () {
6+
it("exists", function () {
7+
expect(InAppBrowser.isAvailable).toBeDefined()
8+
})
9+
10+
it("supported", async function () {
11+
if (application.android ||
12+
(application.ios && utils.ios.MajorVersion >= 9)) {
13+
expect(await InAppBrowser.isAvailable()).toBeTruthy()
14+
}
15+
else {
16+
expect(await InAppBrowser.isAvailable()).toBeFalsy()
17+
}
18+
})
19+
})
20+
21+
describe("open", function () {
22+
it("exists", function () {
523
expect(InAppBrowser.open).toBeDefined()
624
})
725
})
826

9-
describe("close function", function () {
10-
it("exist", function () {
27+
describe("close", function () {
28+
it("exists", function () {
1129
expect(InAppBrowser.close).toBeDefined()
1230
})
1331
})
1432

15-
describe("openAuth function", function () {
16-
it("exist", function () {
33+
describe("openAuth", function () {
34+
it("exists", function () {
1735
expect(InAppBrowser.openAuth).toBeDefined()
1836
})
1937
})
2038

21-
describe("closeAuth function", function () {
22-
it("exist", function () {
39+
describe("closeAuth", function () {
40+
it("exists", function () {
2341
expect(InAppBrowser.closeAuth).toBeDefined()
2442
})
2543
})

src/InAppBrowser.ios.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type InAppBrowserOptions = {
1717
const InAppBrowser = (<any>NSObject).extend({
1818
redirectResolve: null,
1919
redirectReject: null,
20-
authSession: <SFAuthenticationSession> null,
20+
authSession: <SFAuthenticationSession | ASWebAuthenticationSession> null,
2121
isAvailable(): Promise<boolean> {
2222
return Promise.resolve(ios.MajorVersion >= 9);
2323
},
@@ -83,7 +83,7 @@ const InAppBrowser = (<any>NSObject).extend({
8383
if (!self.initializeWebBrowser(resolve, reject)) return;
8484

8585
const url = NSURL.URLWithString(authUrl);
86-
const authSession = SFAuthenticationSession.alloc().initWithURLCallbackURLSchemeCompletionHandler(
86+
self.authSession = (ios.MajorVersion >= 12 ? ASWebAuthenticationSession : SFAuthenticationSession).alloc().initWithURLCallbackURLSchemeCompletionHandler(
8787
url,
8888
redirectUrl,
8989
function (callbackURL, error) {
@@ -101,8 +101,7 @@ const InAppBrowser = (<any>NSObject).extend({
101101
self.flowDidFinish();
102102
}
103103
);
104-
authSession.start();
105-
self.authSession = authSession;
104+
self.authSession.start();
106105
});
107106
}
108107
else {
@@ -116,7 +115,7 @@ const InAppBrowser = (<any>NSObject).extend({
116115
},
117116
closeAuth() {
118117
if (ios.MajorVersion >= 11) {
119-
const authSession: SFAuthenticationSession = this.authSession;
118+
const authSession: SFAuthenticationSession | ASWebAuthenticationSession = this.authSession;
120119
authSession.cancel();
121120
if (this.redirectResolve) {
122121
this.redirectResolve({
@@ -129,9 +128,6 @@ const InAppBrowser = (<any>NSObject).extend({
129128
this.close();
130129
}
131130
},
132-
safariViewControllerDidCompleteInitialLoad(controller: SFSafariViewController, didLoadSuccessfully: boolean): void {
133-
console.log('Delegate, safariViewControllerDidCompleteInitialLoad: ' + didLoadSuccessfully);
134-
},
135131
safariViewControllerDidFinish(controller: SFSafariViewController): void {
136132
if (this.redirectResolve) {
137133
this.redirectResolve({

src/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-inappbrowser",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "InAppBrowser for NativeScript",
55
"main": "InAppBrowser",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)