Created
July 5, 2023 15:49
-
-
Save sodove/b6103a1354036b07b9903b18e339efd8 to your computer and use it in GitHub Desktop.
createShareIntent
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
import platform.UIKit.UIActivityViewController | |
import platform.UIKit.UIApplication | |
internal actual fun createShareIntent(message: String) { | |
val appDelegate = UIApplication.sharedApplication.delegate | |
val rootViewController = appDelegate?.window?.rootViewController | |
if (rootViewController != null) { | |
val activityItems = listOf(message) | |
val activityController = UIActivityViewController( | |
activityItems = activityItems, | |
applicationActivities = null | |
) | |
try { | |
rootViewController.presentViewController( | |
viewControllerToPresent = activityController, | |
animated = true, | |
completion = null | |
) | |
} catch (e: Exception) { | |
slog.e { "failed to presentViewController: $e" } | |
} | |
} else { | |
slog.e { "failed to get rootViewController" } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment