Skip to content

Commit b33c47e

Browse files
committed
added runtime permissions
1 parent 8316223 commit b33c47e

File tree

9 files changed

+168
-45
lines changed

9 files changed

+168
-45
lines changed

config.xml

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1+
<?xml version='1.0' encoding='utf-8'?>
22
<widget id="com.ionicframework.ionic2components639837" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
3-
<name>Ionic2Components</name>
4-
<description>An awesome Ionic/Cordova app.</description>
5-
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
6-
<content src="index.html"/>
7-
<access origin="*"/>
8-
<allow-intent href="http://*/*"/>
9-
<allow-intent href="https://*/*"/>
10-
<allow-intent href="tel:*"/>
11-
<allow-intent href="sms:*"/>
12-
<allow-intent href="mailto:*"/>
13-
<allow-intent href="geo:*"/>
14-
<platform name="android">
15-
<allow-intent href="market:*"/>
16-
</platform>
17-
<platform name="ios">
18-
<allow-intent href="itms:*"/>
19-
<allow-intent href="itms-apps:*"/>
20-
</platform>
21-
<preference name="webviewbounce" value="false"/>
22-
<preference name="UIWebViewBounce" value="false"/>
23-
<preference name="DisallowOverscroll" value="true"/>
24-
<preference name="android-minSdkVersion" value="16"/>
25-
<preference name="BackupWebStorage" value="none"/>
26-
<preference name="SplashScreenDelay" value="0"/>
27-
<preference name="FadeSplashScreen" value="false"/>
28-
<preference name="FadeSplashScreenDuration" value="0"/>
29-
<preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF"/>
30-
<feature name="StatusBar">
31-
<param name="ios-package" onload="true" value="CDVStatusBar"/>
32-
</feature>
33-
<plugin name="cordova-plugin-device" spec="~1.1.3"/>
34-
<plugin name="cordova-plugin-console" spec="~1.0.4"/>
35-
<plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
36-
<plugin name="cordova-plugin-splashscreen" spec="~4.0.0"/>
37-
<plugin name="cordova-plugin-statusbar" spec="~2.2.0"/>
38-
<plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
39-
<plugin name="cordova-plugin-camera" spec="~2.3.0"/>
40-
<plugin name="card.io.cordova.mobilesdk" spec="https://github.com/card-io/card.io-Cordova-Plugin"/>
41-
<allow-navigation href="http://192.168.153.117:8100"/>
42-
</widget>
3+
<name>Ionic2Components</name>
4+
<description>An awesome Ionic/Cordova app.</description>
5+
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
6+
<content src="index.html" />
7+
<access origin="*" />
8+
<allow-intent href="http://*/*" />
9+
<allow-intent href="https://*/*" />
10+
<allow-intent href="tel:*" />
11+
<allow-intent href="sms:*" />
12+
<allow-intent href="mailto:*" />
13+
<allow-intent href="geo:*" />
14+
<platform name="android">
15+
<allow-intent href="market:*" />
16+
</platform>
17+
<platform name="ios">
18+
<allow-intent href="itms:*" />
19+
<allow-intent href="itms-apps:*" />
20+
</platform>
21+
<preference name="webviewbounce" value="false" />
22+
<preference name="UIWebViewBounce" value="false" />
23+
<preference name="DisallowOverscroll" value="true" />
24+
<preference name="android-minSdkVersion" value="16" />
25+
<preference name="BackupWebStorage" value="none" />
26+
<preference name="SplashScreenDelay" value="0" />
27+
<preference name="FadeSplashScreen" value="false" />
28+
<preference name="FadeSplashScreenDuration" value="0" />
29+
<preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF" />
30+
<feature name="StatusBar">
31+
<param name="ios-package" onload="true" value="CDVStatusBar" />
32+
</feature>
33+
<plugin name="cordova-plugin-device" spec="~1.1.3" />
34+
<plugin name="cordova-plugin-console" spec="~1.0.4" />
35+
<plugin name="cordova-plugin-whitelist" spec="~1.3.0" />
36+
<plugin name="cordova-plugin-splashscreen" spec="~4.0.0" />
37+
<plugin name="cordova-plugin-statusbar" spec="~2.2.0" />
38+
<plugin name="ionic-plugin-keyboard" spec="~2.2.1" />
39+
<plugin name="cordova-plugin-camera" spec="~2.3.0" />
40+
<plugin name="card.io.cordova.mobilesdk" spec="https://github.com/card-io/card.io-Cordova-Plugin" />
41+
<allow-navigation href="http://192.168.153.117:8100" />
42+
<plugin name="cordova.plugins.diagnostic" spec="~3.4.1" />
43+
<engine name="android" spec="~6.1.2" />
44+
</widget>

src/app/app.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export class MyApp {
3838
{ title: 'Lists', component: ListsPage },
3939
{ title: 'Cards', component: CardListPage },
4040
{ title: 'Modals', component: ModalsPage },
41-
{ title: 'Slides', component: SlidesPage },
41+
// Removed for now as there were breaking changes in slides
42+
//{ title: 'Slides', component: SlidesPage },
4243
{ title: 'Popup Menu', component: PopupMenuListPage },
4344
{ title: 'Profile', component: ProfileListPage },
4445
{ title: 'Login', component: LoginListPage },

src/app/app.imports.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import { MessagesPage } from '../pages/miscellaneous/chat/messages/messages';
8585
import { ChatsPage } from '../pages/miscellaneous/chat/chats';
8686
import { BlogPostPage } from '../pages/miscellaneous/blog-post/blog-post';
8787
import { CreditCardScanPage } from '../pages/miscellaneous/credit-card-scan/credit-card-scan';
88+
import { RuntimePermissionsPage } from '../pages/miscellaneous/runtime-permissions/runtime-permissions';
8889

8990
// Providers
9091
import { WeatherService } from '../pages/miscellaneous/weather/weather.service';
@@ -140,6 +141,7 @@ export const Pages = [
140141
MessagesPage,
141142
BlogPostPage,
142143
ChartsPage,
144+
RuntimePermissionsPage,
143145

144146
// Cards
145147
CardListPage,

src/pages/_home/home.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ <h3>Advanced Ionic 2 Components</h3>
1919
<button class="pop-in" ion-button secondary menuToggle>Toggle Menu</button>
2020
</ion-content>
2121

22-
23-
<sliding-drawer [options]="drawerOptions">
22+
<!--<sliding-drawer [options]="drawerOptions">
2423
<div class="content">
2524
The world is your oyster.
2625
<p>
2726
If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will be your guide.
2827
</p>
2928
</div>
30-
</sliding-drawer>
29+
</sliding-drawer>-->

src/pages/miscellaneous/miscellaneous.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CountdownOnePage } from './countdown/countdown';
1010
import { TestimonialsPage } from './testimonials/testimonials';
1111
import { TinderCardsPage } from './tinder-cards/tinder-cards';
1212
import { Component } from '@angular/core';
13+
import { RuntimePermissionsPage } from './runtime-permissions/runtime-permissions';
1314

1415
import { NavController, MenuController } from 'ionic-angular';
1516

@@ -63,6 +64,10 @@ export class MiscellaneousListPage {
6364
title: 'Blog Post',
6465
page: BlogPostPage
6566
},
67+
{
68+
title: 'Runtime User Permissions',
69+
page: RuntimePermissionsPage
70+
},
6671
]
6772
}
6873

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
In order to ask or check for user permissions, the Diagnostic plugin is needed.
2+
3+
Docs: https://ionicframework.com/docs/v2/native/diagnostic/
4+
5+
You have to install the plugin with:
6+
```sh
7+
$ ionic plugin add cordova.plugins.diagnostic --save
8+
```
9+
10+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!--
2+
Generated template for the RuntimePermissions page.
3+
4+
See http://ionicframework.com/docs/v2/components/#navigation for more info on
5+
Ionic pages and navigation.
6+
-->
7+
<ion-header>
8+
9+
<ion-navbar>
10+
<ion-title>RuntimePermissions</ion-title>
11+
</ion-navbar>
12+
13+
</ion-header>
14+
15+
16+
<ion-content padding>
17+
<ion-grid>
18+
<ion-row>
19+
<ion-col>
20+
<button ion-button full (click)="requestPermission(PERMISSION.READ_EXTERNAL)">Read External</button>
21+
</ion-col>
22+
<ion-col>
23+
<button ion-button full (click)="requestPermission(PERMISSION.WRITE_EXTERNAL)">Write External</button>
24+
</ion-col>
25+
</ion-row>
26+
<ion-row>
27+
<ion-col>
28+
<button ion-button full (click)="requestPermission(PERMISSION.CAMERA)">Use Camera</button>
29+
</ion-col>
30+
<ion-col>
31+
<button ion-button full (click)="requestPermission(PERMISSION.READ_CONTACTS)">Read Contacts</button>
32+
</ion-col>
33+
</ion-row>
34+
<ion-row>
35+
<ion-col>
36+
<button ion-button full (click)="requestPermission(PERMISSION.RECORD_AUDIO)">Record Audio</button>
37+
</ion-col>
38+
<ion-col>
39+
<button ion-button full (click)="requestPermission(PERMISSION.CALL_PHONE)">Call Phone</button>
40+
</ion-col>
41+
</ion-row>
42+
</ion-grid>
43+
<button ion-button full (click)="requestAllPermissions()">All requests at once</button>
44+
45+
46+
</ion-content>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
page-runtime-permissions {
2+
3+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Component } from '@angular/core';
2+
import { Diagnostic } from 'ionic-native';
3+
import { NavController, NavParams } from 'ionic-angular';
4+
5+
@Component({
6+
selector: 'page-runtime-permissions',
7+
templateUrl: 'runtime-permissions.html'
8+
})
9+
export class RuntimePermissionsPage {
10+
11+
PERMISSION = {
12+
WRITE_EXTERNAL: Diagnostic.permission.WRITE_EXTERNAL_STORAGE,
13+
READ_EXTERNAL: Diagnostic.permission.READ_EXTERNAL_STORAGE,
14+
CAMERA: Diagnostic.permission.CAMERA,
15+
READ_CONTACTS: Diagnostic.permission.READ_CONTACTS,
16+
RECORD_AUDIO: Diagnostic.permission.RECORD_AUDIO,
17+
CALL_PHONE: Diagnostic.permission.CALL_PHONE,
18+
};
19+
20+
constructor(public navCtrl: NavController, public navParams: NavParams) { }
21+
22+
requestPermission(permission) {
23+
Diagnostic.requestRuntimePermission(permission).then(() => {
24+
console.log('permission granted');
25+
}, error => {
26+
console.error('permission error:', error);
27+
});
28+
}
29+
30+
requestAllPermissions() {
31+
var permissions = Object.keys(this.PERMISSION).map(k => this.PERMISSION[k]);
32+
Diagnostic.requestRuntimePermissions(permissions).then(() => {
33+
console.log('permission granted');
34+
}, error => {
35+
console.error('permission error:', error);
36+
});
37+
}
38+
39+
funca() {
40+
Diagnostic.isCameraAuthorized().then((authorized) => {
41+
if (authorized) {
42+
} else {
43+
Diagnostic.requestContactsAuthorization
44+
Diagnostic.requestContactsAuthorization().then((status) => {
45+
if (status == Diagnostic.permissionStatus.GRANTED) {
46+
47+
} else {
48+
// Permissions not granted
49+
}
50+
});
51+
}
52+
});
53+
}
54+
55+
}

0 commit comments

Comments
 (0)