Example #1
0
        public async Task AddShortcut(Shortcut shortcut)
        {
            if (!_isShortcutsSupported)
            {
                throw new NotSupportedOnDeviceException(NOT_SUPPORTED_ERROR_MESSAGE);
            }

            var type = shortcut.ShortcutId;
            var icon = shortcut.IsEmbeddedIcon
                ? (UIApplicationShortcutIcon)(await _embeddedIconProvider.CreatePlatformIcon(shortcut.Icon))
                : (UIApplicationShortcutIcon)(await _customIconProvider.CreatePlatformIcon(shortcut.Icon));
            var metadata = CreateUriMetadata(shortcut.Uri);

            new NSObject().BeginInvokeOnMainThread(() =>
            {
                var scut = new UIMutableApplicationShortcutItem(type,
                                                                shortcut.Label,
                                                                shortcut.Description,
                                                                icon,
                                                                metadata);

                var scuts = UIApplication.SharedApplication.ShortcutItems.ToList();
                scuts.Add(scut);

                UIApplication.SharedApplication.ShortcutItems = scuts.ToArray();
            });
        }
        private async Task <Uri> GetIconUri(IShortcutIcon shortcutIcon)
        {
            if (shortcutIcon is CustomIcon)
            {
                return(await _customIconProvider.CreatePlatformIcon(shortcutIcon) as Uri);
            }

            return(await _embeddedIconProvider.CreatePlatformIcon(shortcutIcon) as Uri);
        }
        private async Task <Icon> CreateIcon(IShortcutIcon icon)
        {
            try
            {
                if (icon is CustomIcon)
                {
                    return(await _customIconProvider.CreatePlatformIcon(icon) as Icon);
                }

                return(await _embeddedIconProvider.CreatePlatformIcon(icon) as Icon);
            }
            catch (Exception ex)
            {
                Log.Error(nameof(AppShortcutsImplementation), ex.Message, ex);
                return(null);
            }
        }