Skip to content

share ​

go
import "github.com/tangoui/tango/sys/share"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package share opens the system share sheet with text, a URL and/or files: UIActivityViewController on iOS, an ACTION_SEND chooser on Android, NSSharingServicePicker on macOS.

err := share.Share(a, share.Options{Text: "Look at this", URL: "https://example.com"})
if errors.Is(err, share.ErrCanceled) { ... }

Share blocks until the sheet is dismissed (iOS, macOS) or shown (Android, which does not report what the user did). It returns ErrUnsupported where the backend has no share sheet and tango.ErrNotRunning after the app quit. On Android call it from a goroutine, not from a main-thread callback (see docs/mobile.md).

变量 ​

go
var (
	ErrUnsupported = platform.ErrUnsupported
	ErrCanceled    = platform.ErrCanceled
)

函数 ​

func Share ​

go
func Share(a *tango.App, o Options) error

Share shows the share sheet and waits for the user.

类型 ​

Options ​

go
type Options struct {
	Text  string
	URL   string
	Files []string // paths of existing files
	Title string   // chooser title (Android) / subject for mail
}

Options is what to share. At least one of Text, URL and Files is needed.

以 MIT 许可发布