Skip to content

Commit

Permalink
Merge pull request #997 from OneSignal/push-to-start-live-activities
Browse files Browse the repository at this point in the history
Push to Start Live Activities
  • Loading branch information
brismithers authored May 31, 2024
2 parents 94aa069 + d329618 commit a55494e
Show file tree
Hide file tree
Showing 23 changed files with 664 additions and 25 deletions.
206 changes: 205 additions & 1 deletion example/IonicCapOneSignal/ios/App/App.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions example/IonicCapOneSignal/ios/App/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>test always and when in use</string>
<key>NSLocationUsageDescription</key>
<string>Test Location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Test Location2</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>test always and when in use</string>
<key>NSSupportsLiveActivities</key>
<true/>
<key>OneSignal_disable_badge_clearing</key>
<false/>
<key>OneSignal_require_privacy_consent</key>
Expand Down
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,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"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,20 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ExampleWidgetBundle.swift
// ExampleWidget
//
// Created by Brian Smith on 4/30/24.
// Copyright © 2024 The Chromium Authors. All rights reserved.
//

import WidgetKit
import SwiftUI

@main
struct ExampleWidgetBundle: WidgetBundle {
var body: some Widget {
ExampleWidgetLiveActivity()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// ExampleWidgetLiveActivity.swift
// ExampleWidget
//
// Created by Brian Smith on 4/30/24.
// Copyright © 2024 The Chromium Authors. All rights reserved.
//

import ActivityKit
import WidgetKit
import SwiftUI
import OneSignalLiveActivities

struct ExampleWidgetLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: DefaultLiveActivityAttributes.self) { context in
// Lock screen/banner UI goes here\VStack(alignment: .leading) {
VStack {
Spacer()
Text("CORDOVA: " + (context.attributes.data["title"]?.asString() ?? "")).font(.headline)
Spacer()
HStack {
Spacer()
Label {
Text(context.state.data["message"]?.asDict()?["en"]?.asString() ?? "")
} icon: {
Image("onesignaldemo")
.resizable()
.scaledToFit()
.frame(width: 40.0, height: 40.0)
}
Spacer()
}
Text("INT: " + String(context.state.data["intValue"]?.asInt() ?? 0))
Text("DBL: " + String(context.state.data["doubleValue"]?.asDouble() ?? 0.0))
Text("BOL: " + String(context.state.data["boolValue"]?.asBool() ?? false))
Spacer()
}
.activitySystemActionForegroundColor(.black)
.activityBackgroundTint(.white)
} dynamicIsland: { _ 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)
}
}
}
11 changes: 11 additions & 0 deletions example/IonicCapOneSignal/ios/App/ExampleWidget/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
4 changes: 4 additions & 0 deletions example/IonicCapOneSignal/ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ end
target 'OneSignalNotificationServiceExtension' do
pod 'OneSignalXCFramework', '>= 5.0', '< 6.0'
end

target 'ExampleWidgetExtension' do
pod 'OneSignalXCFramework', '>= 5.0', '< 6.0'
end
37 changes: 21 additions & 16 deletions example/IonicCapOneSignal/ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,49 @@ PODS:
- Capacitor
- CordovaPluginsStatic (6.0.0):
- CapacitorCordova
- OneSignalXCFramework (= 5.1.6)
- OneSignalXCFramework (5.1.6):
- OneSignalXCFramework/OneSignalComplete (= 5.1.6)
- OneSignalXCFramework/OneSignal (5.1.6):
- OneSignalXCFramework (= 5.2.0)
- OneSignalXCFramework (5.2.0):
- OneSignalXCFramework/OneSignalComplete (= 5.2.0)
- OneSignalXCFramework/OneSignal (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalExtension
- OneSignalXCFramework/OneSignalLiveActivities
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalComplete (5.1.6):
- OneSignalXCFramework/OneSignalComplete (5.2.0):
- OneSignalXCFramework/OneSignal
- OneSignalXCFramework/OneSignalInAppMessages
- OneSignalXCFramework/OneSignalLocation
- OneSignalXCFramework/OneSignalCore (5.1.6)
- OneSignalXCFramework/OneSignalExtension (5.1.6):
- OneSignalXCFramework/OneSignalCore (5.2.0)
- OneSignalXCFramework/OneSignalExtension (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalInAppMessages (5.1.6):
- OneSignalXCFramework/OneSignalInAppMessages (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalLocation (5.1.6):
- OneSignalXCFramework/OneSignalLiveActivities (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalLocation (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
- OneSignalXCFramework/OneSignalUser
- OneSignalXCFramework/OneSignalNotifications (5.1.6):
- OneSignalXCFramework/OneSignalNotifications (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalExtension
- OneSignalXCFramework/OneSignalOutcomes
- OneSignalXCFramework/OneSignalOSCore (5.1.6):
- OneSignalXCFramework/OneSignalOSCore (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalOutcomes (5.1.6):
- OneSignalXCFramework/OneSignalOutcomes (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalUser (5.1.6):
- OneSignalXCFramework/OneSignalUser (5.2.0):
- OneSignalXCFramework/OneSignalCore
- OneSignalXCFramework/OneSignalNotifications
- OneSignalXCFramework/OneSignalOSCore
Expand Down Expand Up @@ -92,9 +97,9 @@ SPEC CHECKSUMS:
CapacitorHaptics: 9ebc9363f0e9b8eb4295088a0b474530acf1859b
CapacitorKeyboard: deacbd09d8d1029c3681197fb05d206b721d5f73
CapacitorStatusBar: 2e4369f99166125435641b1908d05f561eaba6f6
CordovaPluginsStatic: 0c92d460153b745e1dfbe367288a104177b55e46
OneSignalXCFramework: f6533cc1f7a5ddded80ee5fe183901a99ad46f4f
CordovaPluginsStatic: 3355cb91038bf10f85a071f96c435dcabc8cc8ae
OneSignalXCFramework: bdf74fdc06888f9466dc21e826fe1549ed143095

PODFILE CHECKSUM: c53c4ae8125a20193a7e94262437a687b59eaebb
PODFILE CHECKSUM: 178e2a2e451311a871c2b4db713ac4b63d0ebeeb

COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion example/IonicCapOneSignal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions example/IonicCapOneSignal/src/OSButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,72 @@ class OSButtons extends React.Component<Props> {
];
}

createLiveActivitiesFields() {
const { loggingFunction } = this.props;

const startDefaultLiveActivityButton = renderButtonView(
'Start Default',
async () => {
const activityId = this.props.inputFieldValue;
loggingFunction('Start Default Live Activity: ', activityId);
await OneSignal.LiveActivities.startDefault(
activityId,
{ title: 'Welcome!' },
{
message: {en: 'Hello World!'},
intValue: 3,
doubleValue: 3.14,
boolValue: true,
},
);
},
);

const getEnterLiveActivityButton = renderButtonView(
'Enter Live Activity',
async () => {
const activityId = this.props.inputFieldValue;
loggingFunction('Enter Live Activity: ', activityId);
await OneSignal.LiveActivities.enter(activityId, "FAKE_TOKEN");
},
);

const getExitLiveActivityButton = renderButtonView(
'Exit Live Activity',
async () => {
const activityId = this.props.inputFieldValue;
loggingFunction('Exit Live Activity: ', activityId);
await OneSignal.LiveActivities.exit(activityId);
}
);

const getSetupPushToStartButton = renderButtonView(
'Setup Push To Start',
() => {
const activityType = this.props.inputFieldValue;
loggingFunction('Setting up push to start: ', activityType);
OneSignal.LiveActivities.setPushToStartToken(activityType, "FAKE_TOKEN");
}
);

const getRemovePushToStartButton = renderButtonView(
'Remove Push To Start',
() => {
const activityType = this.props.inputFieldValue;
loggingFunction('Remove push to start: ', activityType);
OneSignal.LiveActivities.removePushToStartToken(activityType);
}
);

return [
startDefaultLiveActivityButton,
getEnterLiveActivityButton,
getExitLiveActivityButton,
getSetupPushToStartButton,
getRemovePushToStartButton,
];
}

createPrivacyConsentFields() {
const { loggingFunction } = this.props;

Expand Down Expand Up @@ -486,6 +552,8 @@ class OSButtons extends React.Component<Props> {
<div>{this.createUserFields()}</div>
<IonText className='ion-text-center'><h5>Push Subscription</h5></IonText>
<div>{this.createPushSubscriptionFields()}</div>
<IonText className='ion-text-center'><h5>Live Activities</h5></IonText>
<div>{this.createLiveActivitiesFields()}</div>
<IonText className='ion-text-center'><h5>Privacy Consent</h5></IonText>
<div>{this.createPrivacyConsentFields()}</div>
</IonContent>
Expand Down
3 changes: 2 additions & 1 deletion example/IonicCapOneSignal/src/OSDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class OSDemo extends React.Component<Props, State> {
}

async componentDidMount() {
OneSignal.initialize(APP_ID);
OneSignal.Debug.setLogLevel(LogLevel.Verbose);
OneSignal.initialize(APP_ID);
OneSignal.LiveActivities.setupDefault();

OneSignal.Notifications.addEventListener(
'foregroundWillDisplay',
Expand Down
Loading

0 comments on commit a55494e

Please sign in to comment.