Skip to content

Commit

Permalink
Try-Catch
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Aug 28, 2017
1 parent 70b9fdd commit bb24b42
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
53 changes: 30 additions & 23 deletions src/app-icon-changer.ios.ts
Expand Up @@ -24,32 +24,39 @@ export class AppIconChanger implements AppIconChangerApi {

changeIcon(options: AppIconChangeOptions): Promise<any> {
return new Promise((resolve, reject) => {
if (!this.isSupported()) {
reject("This version of iOS doesn't support alternate icons");
return;
}
try {
if (!this.isSupported()) {
reject("This version of iOS doesn't support alternate icons");
return;
}

if (!options.iconName) {
reject("The 'iconName' parameter is mandatory");
return;
}
if (!options.iconName) {
reject("The 'iconName' parameter is mandatory");
return;
}

// note that this icon must be listed in the app's plist
application.ios.nativeApp.setAlternateIconNameCompletionHandler(
options.iconName,
(error? : NSError) => {
if (error !== null) {
reject({
code: error.code,
message: error.localizedDescription
});
} else {
resolve();
}
});
// note that this icon must be listed in the app's plist
application.ios.nativeApp.setAlternateIconNameCompletionHandler(
options.iconName,
(error?: NSError) => {
if (error !== null) {
reject({
code: error.code,
message: error.localizedDescription
});
} else {
resolve();
}
});

if (options.suppressUserNotification !== false) {
this._suppressUserNotification();
if (options.suppressUserNotification !== false) {
this._suppressUserNotification();
}
} catch (e) {
reject({
code: -1,
message: e
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
@@ -1,6 +1,6 @@
{
"name": "nativescript-app-icon-changer",
"version": "1.0.1",
"version": "1.0.2",
"description": "Change the homescreen icon of your app from code",
"main": "app-icon-changer",
"typings": "index.d.ts",
Expand Down

0 comments on commit bb24b42

Please sign in to comment.