Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Live Activity to example project #1150

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 74 additions & 58 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSSupportsLiveActivities</key>
<true/>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>UIUserInterfaceStyle</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// LiveActivityController.swift
// OneSignalExample
//
// Created by Henry Boswell on 11/9/22.
// Copyright © 2022 OneSignal. All rights reserved.
//

import Foundation
import ActivityKit
import UserNotifications

struct OneSignalWidgetAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
// Dynamic stateful properties about your activity go here!
var message: String
}

// Fixed non-changing properties about your activity go here!
var title: String
}
@objc
class LiveActivityController: NSObject {
@objc
static func createActivity() {
if #available(iOS 16.1, *) {
let attributes = OneSignalWidgetAttributes(title: "OneSignal Dev App Live Activity")
let contentState = OneSignalWidgetAttributes.ContentState(message: "Update this message through push or with Activity Kit")
do {

let _ = try Activity<OneSignalWidgetAttributes>.request(
attributes: attributes,
contentState: contentState,
pushType: .token)
} catch (let error) {
print(error.localizedDescription)
}
} else {
// Fallback on earlier versions
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

5 changes: 5 additions & 0 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#import "ViewController.h"
#import "AppDelegate.h"
#import "OneSignalExample-Swift.h"

@implementation ViewController

Expand Down Expand Up @@ -243,4 +244,8 @@ - (IBAction)sendUniqueOutcomeEvent:(id)sender {
}];
}

- (IBAction)startLiveActivity:(id)sender {
[LiveActivityController createActivity];
}

@end
326 changes: 326 additions & 0 deletions iOS_SDK/OneSignalDevApp/OneSignalExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "onesignal-logo.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions iOS_SDK/OneSignalDevApp/OneSignalWidgetExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSSupportsLiveActivities</key>
<true/>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>INEnums</key>
<array/>
<key>INIntentDefinitionModelVersion</key>
<string>1.2</string>
<key>INIntentDefinitionNamespace</key>
<string>88xZPY</string>
<key>INIntentDefinitionSystemVersion</key>
<string>20A294</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>12A6144</string>
<key>INIntentDefinitionToolsVersion</key>
<string>12.0</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>information</string>
<key>INIntentDescriptionID</key>
<string>tVvJ9c</string>
<key>INIntentEligibleForWidgets</key>
<true/>
<key>INIntentIneligibleForSuggestions</key>
<true/>
<key>INIntentName</key>
<string>Configuration</string>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Configuration</string>
<key>INIntentTitleID</key>
<string>gpCwrM</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>View</string>
</dict>
</array>
<key>INTypes</key>
<array/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// OneSignalWidgetExtensionBundle.swift
// OneSignalWidgetExtension
//
// Created by Henry Boswell on 11/9/22.
// Copyright © 2022 OneSignal. All rights reserved.
//

import WidgetKit
import SwiftUI

@main
struct OneSignalWidgetExtensionBundle: WidgetBundle {
var body: some Widget {
OneSignalWidgetExtensionLiveActivity()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// OneSignalWidgetExtensionLiveActivity.swift
// OneSignalWidgetExtension
//
// Created by Henry Boswell on 11/9/22.
// Copyright © 2022 OneSignal. All rights reserved.
//

import ActivityKit
import WidgetKit
import SwiftUI


struct OneSignalWidgetExtensionLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: OneSignalWidgetAttributes.self) { context in
// Lock screen/banner UI goes here\VStack(alignment: .leading) {
VStack {
Spacer()
Text(context.attributes.title).font(.headline)
Spacer()
HStack {
Spacer()
Label {
Text(context.state.message)
} icon: {
Image("onesignaldemo")
.resizable()
.scaledToFit()
.frame(width: 40.0, height: 40.0)
}
Spacer()
}
Spacer()
}
.activitySystemActionForegroundColor(.black)
.activityBackgroundTint(.white)
} dynamicIsland: { context in
DynamicIsland {
// Expanded UI goes here. Compose the expanded UI through
// various regions, like leading/trailing/center/bottom
DynamicIslandExpandedRegion(.leading) {
Text("Leading")
}
DynamicIslandExpandedRegion(.trailing) {
Text("Trailing")
}
DynamicIslandExpandedRegion(.bottom) {
Text("Bottom")
// more content
}
} compactLeading: {
Text("L")
} compactTrailing: {
Text("T")
} minimal: {
Text("Min")
}
.widgetURL(URL(string: "http://www.apple.com"))
.keylineTint(Color.red)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>