Skip to content

Commit

Permalink
iOS: add new options, fix dependencies, bump version to 0.1.0 (#12)
Browse files Browse the repository at this point in the history
* Add new iOS options, open settings async
* Fix dependencies + lint
* Bump Gradle to v7
  • Loading branch information
dennisameling authored Oct 25, 2021
1 parent 5c3658a commit dd611ab
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 44 deletions.
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# capacitor-native-settings

Capacitor plugin to open native settings screens for android and iOS.
Capacitor plugin to open native settings screens for Android and iOS.

## Install

Expand All @@ -18,6 +18,11 @@ NativeSettings.openAndroid({
option: AndroidSettings.ApplicationDetails,
});

/**
* Note that the only supported option by Apple is "App".
* Using other options might break in future iOS versions
* or have your app rejected from the App Store.
*/
NativeSettings.openIOS({
option: IOSSettings.App,
});
Expand Down Expand Up @@ -55,11 +60,14 @@ Opens the specified option in android.


### openIOS(...)

```typescript
openIOS(option: IOSOptions) => any
```

Opens the specified option in android.
Opens the specified option on iOS.
Note that the only supported option by Apple is "App". Using other options
might break in future iOS versions or have your app rejected in the App Store.

| Param | Type | Description |
| ------------ | ------------------------------------------------- | ------------------------------------ |
Expand Down Expand Up @@ -141,9 +149,33 @@ Opens the specified option in android.

#### IOSSettings

| Members | Value | Description |
| ------------- | ---------------------- | ---------------------------------------- |
| **`General`** | <code>'general'</code> | Opens iOS general settings screen. |
| **`App`** | <code>'app'</code> | Opens your app-specific settings screen. |
| Members | Value | Description |
| ------------------------------ | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| **`About`** | <code>'about'</code> | Settings &gt; About page |
| **`App`** | <code>'app'</code> | Opens your app-specific settings screen. Note that this is the only officially supported settings screen by Apple. |
| **`AutoLock`** | <code>'autoLock'</code> | Used to set if and when the screen should be automatically locked. |
| **`Bluetooth`** | <code>'bluetooth'</code> | Bluetooth settings. Allows the users to enable/disable bluetooth and to search for devices. |
| **`DateTime`** | <code>'dateTime'</code> | Date and time settings. |
| **`FaceTime`** | <code>'facetime'</code> | FaceTime settings. |
| **`General`** | <code>'general'</code> | Opens iOS general settings screen. |
| **`Keyboard`** | <code>'keyboard'</code> | Keyboard settings. |
| **`ICloud`** | <code>'iCloud'</code> | iCloud settings. |
| **`ICloudStorageBackup`** | <code>'iCloudStorageBackup'</code> | iCloud Storage and Backup settings. |
| **`International`** | <code>'international'</code> | Language and region settings. |
| **`Music`** | <code>'music'</code> | Music settings. |
| **`Notes`** | <code>'notes'</code> | Notes settings. |
| **`Notifications`** | <code>'notifications'</code> | Notifications settings. |
| **`Phone`** | <code>'phone'</code> | Phone settings. |
| **`Photos`** | <code>'photos'</code> | Photos settings. |
| **`ManagedConfigurationList`** | <code>'managedConfigurationList'</code> | Allows the user to manage configuration profiles that are installed on the phone. |
| **`Reset`** | <code>'reset'</code> | Screen where the user can reset the phone to factory settings. |
| **`Ringtone`** | <code>'ringtone'</code> | Ringtone settings. |
| **`Sounds`** | <code>'sounds'</code> | Used to set phone volume, vibration settings, etc. |
| **`SoftwareUpdate`** | <code>'softwareUpdate'</code> | Software update screen. |
| **`Store`** | <code>'store'</code> | Store settings. |
| **`Wallpaper`** | <code>'wallpaper'</code> | Wallpaper settings. |
| **`WiFi`** | <code>'wifi'</code> | WiFi settings. |
| **`Tethering`** | <code>'tethering'</code> | Tethering settings (used to create a hotspot with mobile data). |
| **`DoNotDisturb`** | <code>'doNotDisturb'</code> | Do Not Disturb settings. |

</docgen-api>
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.android.tools.build:gradle:4.2.1'
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
62 changes: 44 additions & 18 deletions ios/Plugin/NativeSettingsPlugin.swift
Original file line number Diff line number Diff line change
@@ -1,33 +1,59 @@
import Foundation
import Capacitor

/**
* Please read the Capacitor iOS Plugin Development Guide
* here: https://capacitorjs.com/docs/plugins/ios
*/
@objc(NativeSettingsPlugin)
public class NativeSettingsPlugin: CAPPlugin {
@objc func openIOS(_ call: CAPPluginCall) {
let value = call.getString("option") ?? ""
var settingsUrl:URL!

if (value == "general") {
settingsUrl = URL(string: "App-Prefs:root=General")
} else if (value == "app") {
var settingsUrl: URL!

let settingsPaths = [
"about": "App-prefs:General&path=About",
"autoLock": "App-prefs:General&path=AUTOLOCK",
"bluetooth": "App-prefs:Bluetooth",
"dateTime": "App-prefs:General&path=DATE_AND_TIME",
"facetime": "App-prefs:FACETIME",
"general": "App-prefs:General",
"keyboard": "App-prefs:General&path=Keyboard",
"iCloud": "App-prefs:CASTLE",
"iCloudStorageBackup": "App-prefs:CASTLE&path=STORAGE_AND_BACKUP",
"international": "App-prefs:General&path=INTERNATIONAL",
"music": "App-prefs:MUSIC",
"notes": "App-prefs:NOTES",
"notifications": "App-prefs:NOTIFICATIONS_ID",
"phone": "App-prefs:Phone",
"photos": "App-prefs:Photos",
"managedConfigurationList": "App-prefs:General&path=ManagedConfigurationList",
"reset": "App-prefs:General&path=Reset",
"ringtone": "App-prefs:Sounds&path=Ringtone",
"sounds": "App-prefs:Sounds",
"softwareUpdate": "App-prefs:General&path=SOFTWARE_UPDATE_LINK",
"store": "App-prefs:STORE",
"wallpaper": "App-prefs:Wallpaper",
"wifi": "App-prefs:WIFI",
"tethering": "App-prefs:INTERNET_TETHERING",
"doNotDisturb": "App-prefs:DO_NOT_DISTURB"
]

if settingsPaths[value] != nil {
settingsUrl = URL(string: settingsPaths[value]!)
} else if value == "app" {
settingsUrl = URL(string: UIApplication.openSettingsURLString)
} else {
call.reject("Requested setting \"" + value + "\" is not available on iOS.");
call.reject("Requested setting \"" + value + "\" is not available on iOS.")
return
}

if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
call.resolve([
"status": success
])
})
} else {
call.reject("Cannot open settings")
DispatchQueue.main.async {
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
call.resolve([
"status": success
])
})
} else {
call.reject("Cannot open settings")
}
}
}
}
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-native-settings",
"version": "0.0.3",
"version": "0.1.0",
"description": "Capacitor plugin to open native settings screens for android and iOS",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -44,10 +44,10 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@capacitor/android": "next",
"@capacitor/core": "next",
"@capacitor/android": "^3.0.0",
"@capacitor/core": "^3.0.0",
"@capacitor/docgen": "^0.0.10",
"@capacitor/ios": "next",
"@capacitor/ios": "^3.0.0",
"@ionic/eslint-config": "^0.3.0",
"@ionic/prettier-config": "^1.0.1",
"@ionic/swiftlint-config": "^1.1.2",
Expand All @@ -60,7 +60,7 @@
"typescript": "~4.0.3"
},
"peerDependencies": {
"@capacitor/core": "next"
"@capacitor/core": "^3.0.0"
},
"prettier": "@ionic/prettier-config",
"swiftlint": "@ionic/swiftlint-config",
Expand Down
129 changes: 126 additions & 3 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export interface NativeSettingsPlugin {
openAndroid(option: AndroidOptions): Promise<{ status: boolean }>;

/**
* Opens the specified option in android.
* Opens the specified option on iOS.
* Note that the only supported option by Apple is "App". Using other options
* might break in future iOS versions or have your app rejected in the App Store.
*
* @param option IOSOptions
* @see IOSOptions
*/
Expand Down Expand Up @@ -240,13 +243,133 @@ export enum AndroidSettings {
}

export enum IOSSettings {
/**
* Settings > About page
*/
About = 'about',

/**
* Opens your app-specific settings screen. Note that this is the only officially supported settings screen by Apple.
*/
App = 'app',

/**
* Used to set if and when the screen should be automatically locked.
*/
AutoLock = 'autoLock',

/**
* Bluetooth settings. Allows the users to enable/disable bluetooth and to search for devices.
*/
Bluetooth = 'bluetooth',

/**
* Date and time settings.
*/
DateTime = 'dateTime',

/**
* FaceTime settings.
*/
FaceTime = 'facetime',

/**
* Opens iOS general settings screen.
*/
General = 'general',

/**
* Opens your app-specific settings screen.
* Keyboard settings.
*/
App = 'app',
Keyboard = 'keyboard',

/**
* iCloud settings.
*/
ICloud = 'iCloud',

/**
* iCloud Storage and Backup settings.
*/
ICloudStorageBackup = 'iCloudStorageBackup',

/**
* Language and region settings.
*/
International = 'international',

/**
* Music settings.
*/
Music = 'music',

/**
* Notes settings.
*/
Notes = 'notes',

/**
* Notifications settings.
*/
Notifications = 'notifications',

/**
* Phone settings.
*/
Phone = 'phone',

/**
* Photos settings.
*/
Photos = 'photos',

/**
* Allows the user to manage configuration profiles that are installed on the phone.
*/
ManagedConfigurationList = 'managedConfigurationList',

/**
* Screen where the user can reset the phone to factory settings.
*/
Reset = 'reset',

/**
* Ringtone settings.
*/
Ringtone = 'ringtone',

/**
* Used to set phone volume, vibration settings, etc.
*/
Sounds = 'sounds',

/**
* Software update screen.
*/
SoftwareUpdate = 'softwareUpdate',

/**
* Store settings.
*/
Store = 'store',

/**
* Wallpaper settings.
*/
Wallpaper = 'wallpaper',

/**
* WiFi settings.
*/
WiFi = 'wifi',

/**
* Tethering settings (used to create a hotspot with mobile data).
*/
Tethering = 'tethering',

/**
* Do Not Disturb settings.
*/
DoNotDisturb = 'doNotDisturb',
}

0 comments on commit dd611ab

Please sign in to comment.