Skip to content

Commit e3d723c

Browse files
committed
add request location example
1 parent 763875f commit e3d723c

File tree

7 files changed

+78
-12
lines changed

7 files changed

+78
-12
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,3 @@ dlcov.log
2323
*.ipr
2424
*.iws
2525
.idea/
26-
27-
# Swift Package Manager
28-
!.gitkeep

example/ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
</dict>
3434
<key>NSSupportsLiveActivities</key>
3535
<true/>
36+
<key>NSLocationWhenInUseUsageDescription</key>
37+
<string>Your location is used to send relevant notifications.</string>
3638
<key>UIApplicationSupportsIndirectInputEvents</key>
3739
<true/>
3840
<key>UILaunchStoryboardName</key>

example/lib/main.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class _MyAppState extends State<MyApp> {
1818
String? _language;
1919
String? _liveActivityId;
2020
bool _enableConsentButton = false;
21+
bool _locationShared = false;
2122

2223
// CHANGE THIS parameter to true if you want to test GDPR privacy consent
2324
bool _requireConsent = false;
@@ -197,8 +198,20 @@ class _MyAppState extends State<MyApp> {
197198
}
198199

199200
void _handleSetLocationShared() {
200-
print("Setting location shared to true");
201-
OneSignal.Location.setShared(true);
201+
_locationShared = !_locationShared;
202+
print("Setting location shared to $_locationShared");
203+
OneSignal.Location.setShared(_locationShared);
204+
setState(() {});
205+
}
206+
207+
void _handleRequestLocationPermission() {
208+
print("Requesting location permission");
209+
OneSignal.Location.requestPermission();
210+
}
211+
212+
void _handleIsLocationShared() async {
213+
var isShared = await OneSignal.Location.isShared();
214+
print('Location shared: $isShared');
202215
}
203216

204217
void _handleGetExternalId() async {
@@ -394,9 +407,17 @@ class _MyAppState extends State<MyApp> {
394407
_enableConsentButton)
395408
]),
396409
new TableRow(children: [
397-
new OneSignalButton("Set Location Shared",
410+
new OneSignalButton("Location Shared: $_locationShared",
398411
_handleSetLocationShared, !_enableConsentButton)
399412
]),
413+
new TableRow(children: [
414+
new OneSignalButton("Request Location",
415+
_handleRequestLocationPermission, !_enableConsentButton)
416+
]),
417+
new TableRow(children: [
418+
new OneSignalButton("Is Location Shared",
419+
_handleIsLocationShared, !_enableConsentButton)
420+
]),
400421
new TableRow(children: [
401422
new OneSignalButton(
402423
"Remove Tag", _handleRemoveTag, !_enableConsentButton)

example_pod/ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
</dict>
3434
<key>NSSupportsLiveActivities</key>
3535
<true/>
36+
<key>NSLocationWhenInUseUsageDescription</key>
37+
<string>Your location is used to send relevant notifications.</string>
3638
<key>UIApplicationSupportsIndirectInputEvents</key>
3739
<true/>
3840
<key>UILaunchStoryboardName</key>

example_pod/lib/main.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class _MyAppState extends State<MyApp> {
1818
String? _language;
1919
String? _liveActivityId;
2020
bool _enableConsentButton = false;
21+
bool _locationShared = false;
2122

2223
// CHANGE THIS parameter to true if you want to test GDPR privacy consent
2324
bool _requireConsent = false;
@@ -197,8 +198,20 @@ class _MyAppState extends State<MyApp> {
197198
}
198199

199200
void _handleSetLocationShared() {
200-
print("Setting location shared to true");
201-
OneSignal.Location.setShared(true);
201+
_locationShared = !_locationShared;
202+
print("Setting location shared to $_locationShared");
203+
OneSignal.Location.setShared(_locationShared);
204+
setState(() {});
205+
}
206+
207+
void _handleRequestLocationPermission() {
208+
print("Requesting location permission");
209+
OneSignal.Location.requestPermission();
210+
}
211+
212+
void _handleIsLocationShared() async {
213+
var isShared = await OneSignal.Location.isShared();
214+
print('Location shared: $isShared');
202215
}
203216

204217
void _handleGetExternalId() async {
@@ -394,9 +407,17 @@ class _MyAppState extends State<MyApp> {
394407
_enableConsentButton)
395408
]),
396409
new TableRow(children: [
397-
new OneSignalButton("Set Location Shared",
410+
new OneSignalButton("Location Shared: $_locationShared",
398411
_handleSetLocationShared, !_enableConsentButton)
399412
]),
413+
new TableRow(children: [
414+
new OneSignalButton("Request Location",
415+
_handleRequestLocationPermission, !_enableConsentButton)
416+
]),
417+
new TableRow(children: [
418+
new OneSignalButton("Is Location Shared",
419+
_handleIsLocationShared, !_enableConsentButton)
420+
]),
400421
new TableRow(children: [
401422
new OneSignalButton(
402423
"Remove Tag", _handleRemoveTag, !_enableConsentButton)

example_spm/ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
</dict>
3434
<key>NSSupportsLiveActivities</key>
3535
<true/>
36+
<key>NSLocationWhenInUseUsageDescription</key>
37+
<string>Your location is used to send relevant notifications.</string>
3638
<key>UIApplicationSupportsIndirectInputEvents</key>
3739
<true/>
3840
<key>UILaunchStoryboardName</key>

example_spm/lib/main.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class _MyAppState extends State<MyApp> {
1818
String? _language;
1919
String? _liveActivityId;
2020
bool _enableConsentButton = false;
21+
bool _locationShared = false;
2122

2223
// CHANGE THIS parameter to true if you want to test GDPR privacy consent
2324
bool _requireConsent = false;
@@ -197,8 +198,20 @@ class _MyAppState extends State<MyApp> {
197198
}
198199

199200
void _handleSetLocationShared() {
200-
print("Setting location shared to true");
201-
OneSignal.Location.setShared(true);
201+
_locationShared = !_locationShared;
202+
print("Setting location shared to $_locationShared");
203+
OneSignal.Location.setShared(_locationShared);
204+
setState(() {});
205+
}
206+
207+
void _handleRequestLocationPermission() {
208+
print("Requesting location permission");
209+
OneSignal.Location.requestPermission();
210+
}
211+
212+
void _handleIsLocationShared() async {
213+
var isShared = await OneSignal.Location.isShared();
214+
print('Location shared: $isShared');
202215
}
203216

204217
void _handleGetExternalId() async {
@@ -394,9 +407,17 @@ class _MyAppState extends State<MyApp> {
394407
_enableConsentButton)
395408
]),
396409
new TableRow(children: [
397-
new OneSignalButton("Set Location Shared",
410+
new OneSignalButton("Location Shared: $_locationShared",
398411
_handleSetLocationShared, !_enableConsentButton)
399412
]),
413+
new TableRow(children: [
414+
new OneSignalButton("Request Location",
415+
_handleRequestLocationPermission, !_enableConsentButton)
416+
]),
417+
new TableRow(children: [
418+
new OneSignalButton("Is Location Shared",
419+
_handleIsLocationShared, !_enableConsentButton)
420+
]),
400421
new TableRow(children: [
401422
new OneSignalButton(
402423
"Remove Tag", _handleRemoveTag, !_enableConsentButton)

0 commit comments

Comments
 (0)