amplitude / amplitude/Amplitude-Swift

Server Side Swift Support

未關閉
#85 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Swift
星號
82
分支
45
平均合併
8 小時 54 分鐘
30 天內合併 PR
7

描述

## Summary

Although the repository specially called out Apple platforms (This is Amplitude's latest version of the iOS SDK, covering iOS/tvOS/macOS/watchOS.), Swift as a language is growing beyond those specific usages. With a few modifications, this library can be adapted to run on other Swift native environments (like Linux and Windows).

## Motivations

I had a [PR](https://github.com/amplitude/Amplitude-Swift/pull/42) that started this work, but recent changes has made it difficult to stay on top keeping it merge-ready. When library developers aren't trained to think about multiple platform support, it's easy to make decisions that directly make that support hard to achieve.

Here are some of the areas identified that would need to be addressed to make this library compatible with non-apple platforms:

### Isolate **OSLog** usage by checking for `#if canImport(os.log)`
* Preferably use a cross-platform solution like [swift-log](https://github.com/apple/swift-log)

### Add conditional imports for `FoundationNetworking` where required. (`#if canImport(FoundationNetworking)`)

* On non-apple platforms, networking classes like `URL`, `URLRequest`, `URLSession` are part of the `FoundationNetworking` package.

### Setup a CSQLite map for linux systems

```
.systemLibrary(
name: "CSQLite",
pkgConfig: "sqlite3",
providers: [
.apt(["sqlite3", "libsqlite3-dev"])
]
),
.target(
name: "AmplitudeSwift",
dependencies: [
.target(name: "CSQLite", condition: .when(platforms: [.linux]))
],
path: "Sources/Amplitude",
exclude: ["../../Examples/", "../../Tests/"]
),
```

### Beware of `DispatchQueue.main`

This may not exist or function differently on other platforms. In a server-side environment, using this queue often does nothing.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。