Created
September 21, 2024 11:19
-
-
Save dalafiarisamuel/f360f9aee864ac5746d51dfe67f17913 to your computer and use it in GitHub Desktop.
Add Ios Dynamic shorcuts to Kotlin Multiplatform App
This file contains hidden or 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
import platform.UIKit.UIApplication | |
import platform.UIKit.UIApplicationShortcutIcon | |
import platform.UIKit.UIApplicationShortcutIconType | |
import platform.UIKit.UIApplicationShortcutItem | |
import platform.UIKit.shortcutItems | |
fun setDynamicAppShortcut() { | |
// Create an icon for the shortcut | |
val shortcutIcon = UIApplicationShortcutIcon.iconWithType(UIApplicationShortcutIconType.UIApplicationShortcutIconTypeSearch) | |
// Create a shortcut item | |
val shortcutItem = UIApplicationShortcutItem( | |
type = "com.tamuno.unsplash.kmp.search_shortcut", | |
localizedTitle = "Search Images", | |
localizedSubtitle = "find images on unsplash", | |
icon = shortcutIcon, | |
userInfo = null | |
) | |
val feelingLuckyIcon = UIApplicationShortcutIcon.iconWithType(UIApplicationShortcutIconType.UIApplicationShortcutIconTypeShuffle) | |
val feelingLucky = UIApplicationShortcutItem( | |
type = "com.tamuno.unsplash.kmp.feeling_lucky_shortcut", | |
localizedTitle = "Feeling Lucky", | |
localizedSubtitle = "random image", | |
icon = feelingLuckyIcon, | |
userInfo = null | |
) | |
// Assign the shortcut item to the application's shortcutItems property | |
UIApplication.sharedApplication().shortcutItems = listOf(shortcutItem, feelingLucky) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment