Skip to content

hyperlinkgroup/appstate-sdk-ios

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

AppState.dev

Swift Package for simple and fast integration of AppState.dev into iOS apps.


Content

Features

  • Fetch active notifications for your app
  • Read notifications as JSON with the integrated decodable model
  • Use one of our template views for SwiftUI, UITableView or UICollectionView
  • Hide notifications (if their type can be dismissed)
  • Restore hidden notifications

Screenshots

SwiftUI

UITableView

UICollectionView

Installation

Requirements

The SDK requires an account for AppState.dev with a registered app.

  • iOS 14.0+ / macOS 12.0
  • Xcode 13+
  • Swift 5+
Swift Package Manager

In Xcode, go to File > Add Packages and add https://github.com/hyperlinkgroup/appstate-sdk-ios. Add the package to all your targets.

How to Use

Fetching Notifications

All active notifications are fetched and kept in the AppStateManager within the package. To initially fetch your notifications you need to import AppState and then set your appID. You can do this in your AppDelegate (UIKit), in your main app (SwiftUI) or in a specific view, where you'd like to start fetching, e.g. in your settings, if - for a specific reason - notifications should only be displayed there after a user shows the view:

let appId = "<Your app's ID>"
AppStateManager.shared.setAppID(appId)

Important: You can find your app's ID in the macOS/iPadOS app by tapping on the info button in your app details.

By setting the ID, your notifications are fetched automatically. From now on, they can be accessed by calling their value:

AppStateManager.shared.states.value

Important: You need to call .value on the states property because they are stored in a CurrentValueSubject using the Combine framework.

The Example directory fetches notifications from a local JSON file containing exemplary notifications. The file represents the answer you get from our API.

Using Templates

You can use the built-in templates for SwiftUI views, UITableViews cells and UICollectionViews cells. When setting up your views, simply import AppState on the top of your file and call the respective view. An exemplary integration for a UICollectionView is as follows:

let appStateCell = UICollectionView.CellRegistration<AppStateCollectionViewCell, SectionItem> { _, _, _ in }

The reusable component here is AppStateCollectionViewCell.

In the Example directory you can find demo code to show how to setup all templates within their respective views.

About

Swift Package for simple and fast integration of AppState.dev into iOS apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages