[TIMOB-19709] Ti.UI.iOS.ApplicationShortcuts.addDynamicShortcut icon does not work with custom images
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | None |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2015-10-13T20:58:47.000+0000 |
| Affected Version/s | Release 5.1.0 |
| Fix Version/s | Release 5.1.0 |
| Components | iOS |
| Labels | n/a |
| Reporter | Fokke Zandbergen |
| Assignee | Hans Knöchel |
| Created | 2015-10-11T15:44:02.000+0000 |
| Updated | 2015-10-21T22:07:05.000+0000 |
Description
When you use a custom image for
Ti.UI.iOS.ApplicationShortcuts.addDynamicShortcut() it won't work because the [source code](https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiUIiOSApplicationShortcutsProxy.m#L182) doesn't [hash the passed image path](https://github.com/appcelerator/titanium_mobile/pull/7248/files) so it work with now we're generate asset catalogs for images with TIMOB-19296.
appShortcuts.addDynamicShortcut({
itemtype: 'my.type',
title: 'My title',
subtitle: 'My subtitle',
// does not work:
// icon: '/images/shortcutItemIcon.png',
// does work
icon: '6ce9fb071294c440a20ff73b7c09fef2082c2206',
});
With PR and https://github.com/appcelerator-developer-relations/appc-sample-3dtouch still doesn't work and seems to be an error in the new code:
gives:-(NSString*)urlInAssetCatalog:(NSString*)url { NSString *resultUrl = nil; NSLog(@"[ERROR] In urlInAssetCatalog"); unsigned char digest[CC_SHA1_DIGEST_LENGTH]; NSData *stringBytes = [url dataUsingEncoding: NSUTF8StringEncoding]; if (CC_SHA1([stringBytes bytes], (CC_LONG)[stringBytes length], digest)) { NSLog(@"[ERROR] In urlInAssetCatalog IF"); // SHA-1 hash has been calculated and stored in 'digest'. NSMutableString *sha = [[NSMutableString alloc] init]; for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) { [sha appendFormat:@"%02x", digest[i]]; } [sha appendString:@"."]; [sha appendString:[url pathExtension]]; NSLog(@"[ERROR] resultUrl %@ wow", sha); resultUrl = sha; RELEASE_TO_NIL(sha) } NSLog(@"[ERROR] resultUrl %@ wow", resultUrl); return resultUrl; }so I guessresultUrlneeds to be a proper copy ofshaorshashould not be nilled. If I remove theRELEASE_TO_NILline or replace the preceding reference with the following copy it works:Also, the current implementation only works for
images/shortcutItemIcon.pngand not/images/shortcutItemIcon.pngwhile the following works fine as it should:So you need to strip the first slash if found.PR (master): https://github.com/appcelerator/titanium_mobile/pull/7290 PR (5_1_X): https://github.com/appcelerator/titanium_mobile/pull/7298
[~fokkezb] Renamed the ticket and adjusted methods to reflect the renamed methods.
Verified as fixed, able to use Ti.UI.iOS.ApplicationShortcuts.addDynamicShortcut() with custom images. Mac OSX El Capitan 10.11 (15A284) Studio: 4.3.3.201510201834 Ti SDK: 5.2.0.v20151020100425 Appc NPM: 4.2.1-5 Appc CLI: 5.2.0-18 Ti CLI: 5.0.4 Xcode 7.0(7A218) Node v4.2.1 iPhone 6S Plus (9.0) production *Closing ticket.*