Skip to content

Instantly share code, notes, and snippets.

@sodove
Created July 5, 2023 15:49
Show Gist options
  • Save sodove/b6103a1354036b07b9903b18e339efd8 to your computer and use it in GitHub Desktop.
Save sodove/b6103a1354036b07b9903b18e339efd8 to your computer and use it in GitHub Desktop.
createShareIntent
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