InAppTools is a library written in Swift that let's you easily add mobile users to your mailing lists.
To use InAppTools, you'll first need to generate an APIKEY. To generate one, sign into https://inapptools.com and select Profile. Then, under "API Keys", click "New API Key" and follow the instructions.
- Xcode 14 / Swift 5.7
- iOS >= 15.0
- macOS >= 12.0
For all the following examples, import the library beforehand:
import InAppTools
To get the id of your mailing list, sign into https://inapptools.com and copy the List ID
of your mailing list.
Once the user has entered their email address, you can subscribe them to a mailing list with:
let member = try await MailingList(apiKey: apiKey).subscribe(listId: listId, email: email)
If the subscribe
method throws an exception, the most likely causes are an incorrect apiKey, or an incorrect listId.
Calling subscribe
with an email that is already subscribed to your mailing list will not cause an error.
The returned member
is a struct with a copy of the saved attributes, along with a uuid
attribute. Save this somewhere
if you want to later offer the user the ability to unsubscribe
There are a number of optional attributes that you can add to a subscription call:
let member = try await MailingList(apiKey: apiKey).subscribe(listId: listId, email: email, firstName: firstName, lastName: lastName, name: name, fields: fields, tags: tags)
- firstName, lastName, name: some mailing list platforms deal differently with a first / last name versus a full name. Prompt the user for whatever suits your mailing list platform and omit the rest.
- fields: a set of key, value pairs that can be used to segment the users later.
- tags: a set of "tags" that should be associated with this user.
The returned member
is a struct with a copy of the saved attributes, along with a uuid
attribute. Save this somewhere
if you want to later offer the user the ability to unsubscribe
let member = try await mailingList.unsubscribe(listId: listId, uuid: uuid)
Unsubscribing a user does not delete their record on the server - it simply marks them as 'unsubscribed'
on the mailing list platform. To re-subscribe them, call the subscribe
function again.
To install InAppTools using Swift Package Manager using Xcode:
- In Xcode, select "File" -> "Add Package Dependencies..."
- Enter https://github.com/dhennessy/inapptools-ios-sdk.git
or you can add the following dependency to your Package.swift
:
.package(url: "https://github.com/dhennessy/inapptools-ios-sdk.git", from: "0.1.0")
Add the following line to your Podfile:
pod 'InAppTools'
See CHANGELOG.md for a list of changes.
If you should hit any issues while using InAppTools, we appreciate bug reports on GitHub Issues.
InAppTools is available under the MIT license. See LICENSE.md for more info.