-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cesar Cavazos
committed
Apr 6, 2017
0 parents
commit 42d85c5
Showing
24 changed files
with
1,083 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/iphone/build | ||
/iphone/*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2017-Present Cesar Cavazos | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
## Alternate App Icon Ti Module (iOS 10.3+) | ||
|
||
### Summary | ||
|
||
Leverage the ability to change the app icon in iOS 10.3+ | ||
|
||
<img src="example/icon_white.png" width="320" alt="WhiteIcon" /><img src="example/icon_black.png" width="320" alt="BlackIcon" /> | ||
|
||
### Requirements | ||
|
||
- Titanium Mobile SDK 6.0.3.GA or later | ||
- iOS 10.3 or later | ||
- Xcode 8.3 or later | ||
|
||
### Download | ||
|
||
* [Stable release](https://github.com/ccavazos/titanium-alternate-icons/releases) | ||
|
||
### Setup | ||
|
||
Unzip the module in the `modules/iphone/` folder of your project. | ||
Add the module requirement in your `tiapp.xml` file. | ||
|
||
```xml | ||
<modules> | ||
<module platform="iphone">ti.alternateicons</module> | ||
</modules> | ||
``` | ||
|
||
In order to use this module with Titanium you will need to disable app thinning by editing the adding the following property in your `tiapp.xml` | ||
|
||
```xml | ||
<ios> | ||
<use-app-thinning>false</use-app-thinning> | ||
</ios> | ||
``` | ||
|
||
Next, you have to declare the icons that you will use in your by adding the following to the `tiapp.xml`. The `<key>` named `alloyIcon` is the string that you will use to call the `setAlternateIconName` method . | ||
|
||
```xml | ||
<ios> | ||
<key>CFBundleIcons</key> | ||
<dict> | ||
<key>CFBundleAlternateIcons</key> | ||
<dict> | ||
<key>alloyIcon</key> | ||
<dict> | ||
<key>CFBundleIconFiles</key> | ||
<array> | ||
<string>alloy</string> | ||
</array> | ||
</dict> | ||
</dict> | ||
<key>CFBundlePrimaryIcon</key> | ||
<dict> | ||
<key>CFBundleIconFiles</key> | ||
<array> | ||
<string>AppIcon</string> | ||
</array> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</ios> | ||
``` | ||
|
||
Copy your icons into the `app/assets/` folder. You can try it out with `[email protected]` and `[email protected]` in the example folder of this repo. | ||
|
||
### Hyperloop | ||
|
||
This module is also built in Hyperloop to demonstrate the native API access with JavaScript. | ||
You can simple require the `ti.alternateicon.js` in your application and run it! | ||
|
||
#### Example | ||
|
||
Request a new review dialog: | ||
|
||
```javascript | ||
var AlternateIcon = require('ti.alternateicon'); | ||
|
||
if (AlternateIcon.isSupported()) { | ||
AlternateIcon.setAlternateIconName('alloyIcon'); | ||
} | ||
``` | ||
#### Methods | ||
|
||
- [x] `isSupported` | ||
- [x] `supportsAlternateIcons` | ||
- [x] `alternateIconName` | ||
- [x] `setAlternateIconName` | ||
- [x] `setDefaultIconName` | ||
|
||
### Author | ||
|
||
Cesar Cavazos ([@cesarcvz](https://twitter.com/cesarcvz) / [Web](http://ccavazos.co)) | ||
|
||
### License | ||
|
||
Apache 2.0 | ||
|
||
### Contributing | ||
|
||
Code contributions are greatly appreciated, please submit a new [pull request](https://github.com/ccavazos/titanium-alternate-icons/pull/new/master) | ||
|
||
### Special Thanks | ||
|
||
To [Hans Knoechel](https://github.com/hansemannn) because this module was created using [titanium-review-dialog](https://github.com/hansemannn/titanium-review-dialog) as a reference |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Make sure you have done the following: | ||
// - Disable App Thining | ||
// - In the tiapp.xml add the following | ||
// - Add the icon images under app/assets/ | ||
var tiAlternateIcons = require('ti.alternateicons'); | ||
console.info('module is => ' + tiAlternateIcons); | ||
|
||
// Validates that iOS is 10.3 or greater | ||
console.info('isSupported: ' + tiAlternateIcons.isSupported()); | ||
// Native method that returns if the alternate icons are supported | ||
console.info('supportsAlternateIcons: ' + tiAlternateIcons.supportsAlternateIcons()); | ||
|
||
// Samp le window | ||
var win = Ti.UI.createWindow({ | ||
backgroundColor: '#FFFFFF' | ||
}); | ||
var buttonSetDefaultIcon = Ti.UI.createButton({ | ||
top: 30, | ||
title: 'Set Default Icon' | ||
}); | ||
var buttonSetAlternateIcon = Ti.UI.createButton({ | ||
top: 80, | ||
title: 'Set Alternate Icon' | ||
}); | ||
var buttonAlternateIcon = Ti.UI.createButton({ | ||
top: 130, | ||
title: 'Get Icon Name' | ||
}); | ||
|
||
buttonSetDefaultIcon.addEventListener('click', function(_evt){ | ||
if (tiAlternateIcons.isSupported() && tiAlternateIcons.supportsAlternateIcons()) { | ||
tiAlternateIcons.setDefaultIconName(); | ||
} else { | ||
alert('Not supported'); | ||
} | ||
}); | ||
buttonSetAlternateIcon.addEventListener('click', function(_evt){ | ||
if (tiAlternateIcons.isSupported() && tiAlternateIcons.supportsAlternateIcons()) { | ||
tiAlternateIcons.setAlternateIconName('alloy'); | ||
} else { | ||
alert('Not supported'); | ||
} | ||
}); | ||
buttonAlternateIcon.addEventListener('click', function(_evt){ | ||
if (tiAlternateIcons.isSupported() && tiAlternateIcons.supportsAlternateIcons()) { | ||
var iconName = tiAlternateIcons.alternateIconName(); | ||
if (iconName) { | ||
alert('Current icon name is: ' + iconName); | ||
} else { | ||
alert('Default icon returns as null'); | ||
} | ||
} else { | ||
alert('Not supported'); | ||
} | ||
}); | ||
|
||
win.add(buttonSetDefaultIcon); | ||
win.add(buttonSetAlternateIcon); | ||
win.add(buttonAlternateIcon); | ||
|
||
win.open(); | ||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Xcode | ||
.DS_Store | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
*.xcworkspace | ||
!default.xcworkspace | ||
xcuserdata | ||
profile | ||
*.moved-aside | ||
DerivedData | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* titanium-alternate-icons | ||
* | ||
* Created by Your Name | ||
* Copyright (c) 2017 Your Company. All rights reserved. | ||
*/ | ||
|
||
#import "TiModule.h" | ||
|
||
@interface TiAlternateiconsModule : TiModule | ||
|
||
- (NSNumber*) isSupported:(id)unused; | ||
- (NSNumber*) supportsAlternateIcons:(id)unused; | ||
- (NSString*) alternateIconName:(id)unused; | ||
- (void) setAlternateIconName:(NSString*)iconName; | ||
- (void) setDefaultIconName:(id)unused; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* titanium-alternate-icons | ||
* | ||
* Created by Your Name | ||
* Copyright (c) 2017 Your Company. All rights reserved. | ||
*/ | ||
|
||
#import "TiAlternateiconsModule.h" | ||
#import "TiBase.h" | ||
#import "TiHost.h" | ||
#import "TiUtils.h" | ||
|
||
@implementation TiAlternateiconsModule | ||
|
||
#pragma mark Internal | ||
|
||
// this is generated for your module, please do not change it | ||
-(id)moduleGUID | ||
{ | ||
return @"1730e6ec-327b-4f48-8705-461178f9db12"; | ||
} | ||
|
||
// this is generated for your module, please do not change it | ||
-(NSString*)moduleId | ||
{ | ||
return @"ti.alternateicons"; | ||
} | ||
|
||
#pragma mark Lifecycle | ||
|
||
-(void)startup | ||
{ | ||
// this method is called when the module is first loaded | ||
// you *must* call the superclass | ||
[super startup]; | ||
|
||
NSLog(@"[INFO] %@ loaded",self); | ||
} | ||
|
||
-(void)shutdown:(id)sender | ||
{ | ||
// this method is called when the module is being unloaded | ||
// typically this is during shutdown. make sure you don't do too | ||
// much processing here or the app will be quit forceably | ||
|
||
// you *must* call the superclass | ||
[super shutdown:sender]; | ||
} | ||
|
||
#pragma mark Cleanup | ||
|
||
-(void)dealloc | ||
{ | ||
// release any resources that have been retained by the module | ||
[super dealloc]; | ||
} | ||
|
||
#pragma Public APIs | ||
|
||
-(NSNumber*)isSupported:(id)unused | ||
{ | ||
#ifdef __IPHONE_10_3 | ||
return NUMBOOL([[[UIDevice currentDevice] systemVersion] compare:@"10.3" options:NSNumericSearch] != NSOrderedAscending); | ||
#else | ||
return NUMBOOL(NO); | ||
#endif | ||
} | ||
|
||
-(NSNumber*)supportsAlternateIcons:(id)unused | ||
{ | ||
ENSURE_ARG_COUNT(unused, 0); | ||
#ifdef __IPHONE_10_3 | ||
return NUMBOOL([[UIApplication sharedApplication] supportsAlternateIcons]); | ||
#else | ||
NSLog(@"[ERROR] Ti.AlternateIcons: This feature is only available on iOS 10.3 and later."); | ||
#endif | ||
} | ||
|
||
-(NSString*)alternateIconName:(id)unused | ||
{ | ||
#ifdef __IPHONE_10_3 | ||
return [[UIApplication sharedApplication] alternateIconName]; | ||
#else | ||
NSLog(@"[ERROR] Ti.AlternateIcons: This feature is only available on iOS 10.3 and later."); | ||
#endif | ||
} | ||
-(void)setAlternateIconName:(NSString*)iconName | ||
{ | ||
ENSURE_STRING(iconName) | ||
#ifdef __IPHONE_10_3 | ||
[[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) { | ||
if (error) { | ||
NSLog(@"[ERROR] Ti.AlternateIcons: %@", [error localizedDescription]); | ||
} else { | ||
NSLog(@"[INFO] Ti.AlternateIcons: Icon has been changed to %@.", iconName); | ||
} | ||
}]; | ||
#else | ||
NSLog(@"[ERROR] Ti.AlternateIcons: This feature is only available on iOS 10.3 and later."); | ||
#endif | ||
} | ||
-(void)setDefaultIconName:(id)unused | ||
{ | ||
ENSURE_ARG_COUNT(unused, 0); | ||
#ifdef __IPHONE_10_3 | ||
[[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) { | ||
if (error) { | ||
NSLog(@"[ERROR] Ti.AlternateIcons: %@", [error localizedDescription]); | ||
} else { | ||
NSLog(@"[INFO] Ti.AlternateIcons: Icon has been changed to Default."); | ||
} | ||
}]; | ||
#else | ||
NSLog(@"[ERROR] Ti.AlternateIcons: This feature is only available on iOS 10.3 and later."); | ||
#endif | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* This is a generated file. Do not edit or your changes will be lost | ||
*/ | ||
|
||
@interface TiAlternateiconsModuleAssets : NSObject | ||
{ | ||
} | ||
- (NSData*) moduleAsset; | ||
- (NSData*) resolveModuleAsset:(NSString*)path; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* This is a generated file. Do not edit or your changes will be lost | ||
*/ | ||
#import "TiAlternateiconsModuleAssets.h" | ||
|
||
extern NSData* filterDataInRange(NSData* thedata, NSRange range); | ||
|
||
@implementation TiAlternateiconsModuleAssets | ||
|
||
- (NSData*) moduleAsset | ||
{ | ||
|
||
|
||
return nil; | ||
} | ||
|
||
- (NSData*) resolveModuleAsset:(NSString*)path | ||
{ | ||
|
||
|
||
return nil; | ||
} | ||
|
||
@end |
Oops, something went wrong.