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

Push to Start Live Activities #107

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
DerivedData/
packages/
TestResults/
Pods/

# globs
Makefile.in
Expand Down
20 changes: 20 additions & 0 deletions OneSignalSDK.DotNet.Android/AndroidLiveActivitiesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,24 @@ public Task<bool> Exit(string activityId)
Console.WriteLine("OneSignal: ExitLiveActivity is available on iOS only");
return Task.FromResult(false);
}

public void RemovePushToStartToken(string activityType)
{
Console.WriteLine("OneSignal: RemovePushToStartToken is available on iOS only");
}

public void SetPushToStartToken(string activityType, string token)
{
Console.WriteLine("OneSignal: SetPushToStartToken is available on iOS only");
}

public void SetupDefault(LiveActivitySetupOptions options = null)
{
Console.WriteLine("OneSignal: SetupDefault is available on iOS only");
}

public void StartDefault(string activityId, IDictionary<string, object> attributes, IDictionary<string, object> content)
{
Console.WriteLine("OneSignal: StartDefault is available on iOS only");
}
}
66 changes: 66 additions & 0 deletions OneSignalSDK.DotNet.Core/LiveActivities/ILiveActivities.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OneSignalSDK.DotNet.Core.LiveActivities
Expand All @@ -19,6 +20,71 @@ public interface ILiveActivitiesManager
/// <param name="activityId">The (app-provided) ID of the activity that is being exited.</param>
/// <returns>Awaitable boolean of whether the operation succeeded or failed</returns>
Task<bool> Exit(string activityId);

/// <summary>
/// Enable the OneSignalSDK to setup the default`DefaultLiveActivityAttributes` structure,
/// which conforms to the `OneSignalLiveActivityAttributes`. When using this function, the
/// widget attributes are owned by the OneSignal SDK, which will allow the SDK to handle the
/// entire lifecycle of the live activity. All that is needed from an app-perspective is to
/// create a Live Activity widget in a widget extension, with a `ActivityConfiguration` for
/// `DefaultLiveActivityAttributes`. This is most useful for users that (1) only have one Live
/// Activity widget and (2) are using a cross-platform framework and do not want to create the
/// cross-platform <-> iOS native bindings to manage ActivityKit.
///
/// Only applies to iOS.
/// </summary>
/// <param name="options">An optional structure to provide for more granular setup options.</param>
void SetupDefault(LiveActivitySetupOptions options = null);

/// <summary>
/// Start a new LiveActivity that is modelled by the default`DefaultLiveActivityAttributes`
/// structure. The `DefaultLiveActivityAttributes` is initialized with the dynamic `attributes`
/// and `content` passed in.
///
/// Only applies to iOS.
/// </summary>
/// <param name="activityId">The activity identifier the live activity on this device will be started
/// and eligible to receive updates for.</param>
/// <param name="attributes">A dynamic type containing the static attributes passed into `DefaultLiveActivityAttributes`.</param>
/// <param name="content">A dynamic type containing the content attributes passed into `DefaultLiveActivityAttributes`.</param>
void StartDefault(string activityId, IDictionary<string, object> attributes, IDictionary<string, object> content);

/// <summary>
/// Indicate this device is capable of receiving pushToStart live activities for the `activityType`.
/// The `activityType` **must** be the name of the struct conforming to `ActivityAttributes` that will be used
/// to start the live activity.
///
/// Only applies to iOS.
/// </summary>
/// <param name="activityType">The name of the specific `ActivityAttributes` structure tied to the live activity.</param>
void SetPushToStartToken(string activityType, string token);
brismithers marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Indicate this device is no longer capable of receiving pushToStart live activities for the `activityType`.
/// The `activityType` **must** be the name of the struct conforming to `ActivityAttributes` that will be used
/// to start the live activity.
///
/// Only applies to iOS.
/// </summary>
/// <param name="activityType">The name of the specific `ActivityAttributes` structure tied to the live activity.</param>
void RemovePushToStartToken(string activityType);
}

/// <summary>
/// The setup options for <see cref="ILiveActivitiesManager.SetupDefault"/>.
/// </summary>
public class LiveActivitySetupOptions
{
/// <summary>
/// When true, OneSignal will listen for pushToStart tokens for the `OneSignalLiveActivityAttributes` structure.
/// </summary>
public bool EnablePushToStart { get; set; }

/// <summary>
/// When true, OneSignal will listen for pushToUpdate tokens for each start live activity that uses the
/// `OneSignalLiveActivityAttributes` structure.
/// </summary>
public bool EnablePushToUpdate { get; set; }
}
}

43 changes: 43 additions & 0 deletions OneSignalSDK.DotNet.iOS.Binding/ApiDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,4 +1015,47 @@ interface OSLiveActivities
[Export ("exit:withSuccess:withFailure:")]
void Exit(string activityId, [NullAllowed] OSResultSuccessBlock successBlock, [NullAllowed] OSFailureBlock failureBlock);
}

[BaseType (typeof(NSObject))]
interface OneSignalLiveActivitiesManagerImpl
{
// +(BOOL)setPushToStartToken:(NSString * _Nonnull)activityType withToken:(NSString * _Nonnull)withToken error:(NSError * _Nullable * _Nullable)error __attribute__((availability(ios, introduced=17.2)));
[Static]
[Export ("setPushToStartToken:withToken:error:")]
bool SetPushToStartToken (string activityType, string withToken, [NullAllowed] out NSError error);

// +(BOOL)removePushToStartToken:(NSString * _Nonnull)activityType error:(NSError * _Nullable * _Nullable)error __attribute__((availability(ios, introduced=17.2)));
[Static]
[Export ("removePushToStartToken:error:")]
bool RemovePushToStartToken (string activityType, [NullAllowed] out NSError error);

// +(void)setupDefaultWithOptions:(LiveActivitySetupOptions * _Nullable)options __attribute__((availability(ios, introduced=16.1)));
[Static]
[Export ("setupDefaultWithOptions:")]
void SetupDefaultWithOptions ([NullAllowed] LiveActivitySetupOptions options);

// +(void)startDefault:(NSString * _Nonnull)activityId attributes:(NSDictionary<NSString *,id> * _Nonnull)attributes content:(NSDictionary<NSString *,id> * _Nonnull)content __attribute__((availability(ios, introduced=16.1)));
[Static]
[Export ("startDefault:attributes:content:")]
void StartDefault (string activityId, NSDictionary<NSString, NSObject> attributes, NSDictionary<NSString, NSObject> content);
}

// @interface LiveActivitySetupOptions : NSObject
[BaseType (typeof(NSObject))]
[DisableDefaultCtor]
interface LiveActivitySetupOptions
{
// @property (nonatomic) BOOL enablePushToStart;
[Export ("enablePushToStart")]
bool EnablePushToStart { get; set; }

// @property (nonatomic) BOOL enablePushToUpdate;
[Export ("enablePushToUpdate")]
bool EnablePushToUpdate { get; set; }

// -(instancetype _Nonnull)initWithEnablePushToStart:(BOOL)enablePushToStart enablePushToUpdate:(BOOL)enablePushToUpdate __attribute__((objc_designated_initializer));
[Export ("initWithEnablePushToStart:enablePushToUpdate:")]
[DesignatedInitializer]
NativeHandle Constructor (bool enablePushToStart, bool enablePushToUpdate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@
<key>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>OneSignalCore.framework/OneSignalCore</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>OneSignalCore.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>OneSignalCore.framework/OneSignalCore</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>OneSignalCore.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>OneSignalCore.framework/Versions/A/OneSignalCore</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-maccatalyst</string>
<key>LibraryPath</key>
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Loading