Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19709] Ti.UI.iOS.ApplicationShortcuts.addDynamicShortcut icon does not work with custom images

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2015-10-13T20:58:47.000+0000
Affected Version/sRelease 5.1.0
Fix Version/sRelease 5.1.0
ComponentsiOS
Labelsn/a
ReporterFokke Zandbergen
AssigneeHans Knöchel
Created2015-10-11T15:44:02.000+0000
Updated2015-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',
	});

Comments

  1. Fokke Zandbergen 2015-10-13

    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:
       -(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;
       }
       
    gives:
       [ERROR] In urlInAssetCatalog
       [ERROR] In urlInAssetCatalog IF
       [ERROR] resultUrl 6ce9fb071294c440a20ff73b7c09fef2082c2206.png wow
       [ERROR] resultUrl [ERROR] resultUrl  wow
       
    so I guess resultUrl needs to be a proper copy of sha or sha should not be nilled. If I remove the RELEASE_TO_NIL line or replace the preceding reference with the following copy it works:
       resultUrl = [NSMutableString stringWithString: sha];
       
  2. Fokke Zandbergen 2015-10-13

    Also, the current implementation only works for images/shortcutItemIcon.png and not /images/shortcutItemIcon.png while the following works fine as it should:
       <ImageView image="/images/shortcutItemIcon.png" />
       <ImageView image="images/shortcutItemIcon.png" />
       
    So you need to strip the first slash if found.
  3. Hans Knöchel 2015-10-13

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/7290 PR (5_1_X): https://github.com/appcelerator/titanium_mobile/pull/7298
  4. Hans Knöchel 2015-10-21

    [~fokkezb] Renamed the ticket and adjusted methods to reflect the renamed methods.
  5. Harry Bryant 2015-10-21

    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.*

JSON Source