Skip to content
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
41 changes: 41 additions & 0 deletions src/ScreenTime/STWebHistory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Diagnostics.CodeAnalysis;

using Foundation;

namespace ScreenTime {
public partial class STWebHistory {
/// <summary>Create a new <see cref="STWebHistory" /> for the specified bundle identifier.</summary>
/// <param name="bundleIdentifier">The bundle identifier whose web history to retrieve.</param>
/// <param name="error">In case of failure, an error describing the failure, otherwise null.</param>
/// <returns>A new <see cref="STWebHistory" />, or null in case of failure.</returns>
public static STWebHistory? Create (string bundleIdentifier, out NSError? error)
{
var rv = new STWebHistory (NSObjectFlag.Empty);
rv.InitializeHandle (rv._InitWithBundleIdentifier (bundleIdentifier, out error), "initWithBundleIdentifier:error:", false);
if (rv.Handle == IntPtr.Zero) {
rv.Dispose ();
return null;
}
return rv;
}

/// <summary>Create a new <see cref="STWebHistory" /> for the specified bundle identifier and browsing profile.</summary>
/// <param name="bundleIdentifier">The bundle identifier whose web history to retrieve.</param>
/// <param name="profileIdentifier">The identifier for the browsing profile whose web histor to retrieve.</param>
/// <param name="error">In case of failure, an error describing the failure, otherwise null.</param>
/// <returns>A new <see cref="STWebHistory" />, or null in case of failure.</returns>
[SupportedOSPlatform ("ios18.4")]
[SupportedOSPlatform ("maccatalyst18.4")]
[SupportedOSPlatform ("macos15.4")]
public static STWebHistory? Create (string bundleIdentifier, NSString profileIdentifier, out NSError? error)
{
var rv = new STWebHistory (NSObjectFlag.Empty);
rv.InitializeHandle (rv._InitWithBundleIdentifier (bundleIdentifier, profileIdentifier, out error), "initWithBundleIdentifier:profileIdentifier:error:", false);
if (rv.Handle == IntPtr.Zero) {
rv.Dispose ();
return null;
}
return rv;
}
}
}
3 changes: 3 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,9 @@ SCRIPTINGBRIDGE_SOURCES = \

# ScreenTime

SCREENTIME_SOURCES = \
ScreenTime/STWebHistory.cs \

# SearchKit

SEARCHKIT_SOURCES = \
Expand Down
42 changes: 40 additions & 2 deletions src/screentime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,41 @@ interface STScreenTimeConfigurationObserver {
[iOS (14, 0)]
[MacCatalyst (14, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface STWebHistory {

#if !XAMCORE_5_0
[Obsolete ("Use the 'Create' method instead, because there's no way to return an error from a constructor.")]
[Export ("initWithBundleIdentifier:error:")]
NativeHandle Constructor (string bundleIdentifier, [NullAllowed] out NSError error);
#endif

#if XAMCORE_5_0
[Internal]
#else
[Internal, Sealed]
#endif
[Export ("initWithBundleIdentifier:error:")]
NativeHandle _InitWithBundleIdentifier (string bundleIdentifier, [NullAllowed] out NSError error);

// STWebHistoryProfileIdentifier is a strongly typed enum, but Apple doesn't define any values for it, so bind as NSString
[iOS (18, 4), MacCatalyst (18, 4), Mac (15, 4)]
[Internal]
[Export ("initWithBundleIdentifier:profileIdentifier:error:")]
NativeHandle _InitWithBundleIdentifier (string bundleIdentifier, [NullAllowed] /* STWebHistoryProfileIdentifier */ NSString profileIdentifier, [NullAllowed] out NSError error);

// STWebHistoryProfileIdentifier is a strongly typed enum, but Apple doesn't define any values for it, so bind as NSString
[iOS (18, 4), MacCatalyst (18, 4), Mac (15, 4)]
[Export ("initWithProfileIdentifier:")]
NativeHandle Constructor ([NullAllowed] /* STWebHistoryProfileIdentifier */ NSString profileIdentifier);

[iOS (18, 4), MacCatalyst (18, 4), Mac (15, 4)]
[Export ("fetchHistoryDuringInterval:completionHandler:")]
[Async]
void FetchHistory (NSDateInterval interval, STWebHistoryFetchHistoryCallback completionHandler);

[iOS (18, 4), MacCatalyst (18, 4), Mac (15, 4)]
[Export ("fetchAllHistoryWithCompletionHandler:")]
[Async]
void FetchHistory (STWebHistoryFetchHistoryCallback completionHandler);

[Export ("deleteHistoryForURL:")]
void DeleteHistory (NSUrl url);
Expand All @@ -63,6 +93,8 @@ interface STWebHistory {
void DeleteAllHistory ();
}

delegate void STWebHistoryFetchHistoryCallback ([NullAllowed] NSSet<NSUrl> urls, [NullAllowed] NSError error);

[iOS (14, 0)]
[MacCatalyst (14, 0)]
[BaseType (typeof (UIViewController))]
Expand All @@ -89,6 +121,12 @@ interface STWebpageController {

[Export ("setBundleIdentifier:error:")]
bool SetBundleIdentifier (string bundleIdentifier, [NullAllowed] out NSError error);

// STWebHistoryProfileIdentifier is a strongly typed enum, but Apple doesn't define any values for it, so bind as NSString
[iOS (18, 4), MacCatalyst (18, 4), Mac (15, 4)]
[Export ("profileIdentifier", ArgumentSemantic.Copy), NullAllowed]
/* STWebHistoryProfileIdentifier */
NSString ProfileIdentifier { get; set; }
}

}
1 change: 0 additions & 1 deletion tests/cecil-tests/ConstructorTest.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public partial class ConstructorTest {
"PencilKit.PKDrawing::.ctor(Foundation.NSData,Foundation.NSError&)",
"Phase.PhaseSoundEvent::.ctor(Phase.PhaseEngine,System.String,Foundation.NSError&)",
"Phase.PhaseSoundEvent::.ctor(Phase.PhaseEngine,System.String,Phase.PhaseMixerParameters,Foundation.NSError&)",
"ScreenTime.STWebHistory::.ctor(System.String,Foundation.NSError&)",
"ShazamKit.SHCustomCatalog::.ctor(Foundation.NSData,Foundation.NSError&)",
"ShazamKit.SHSignature::.ctor(Foundation.NSData,Foundation.NSError&)",
"SoundAnalysis.SNAudioFileAnalyzer::.ctor(Foundation.NSUrl,Foundation.NSError&)",
Expand Down
8 changes: 7 additions & 1 deletion tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35302,10 +35302,14 @@ M:ScreenTime.STScreenTimeConfiguration.EncodeTo(Foundation.NSCoder)
M:ScreenTime.STScreenTimeConfigurationObserver.#ctor(CoreFoundation.DispatchQueue)
M:ScreenTime.STScreenTimeConfigurationObserver.StartObserving
M:ScreenTime.STScreenTimeConfigurationObserver.StopObserving
M:ScreenTime.STWebHistory.#ctor(System.String,Foundation.NSError@)
M:ScreenTime.STWebHistory.#ctor(Foundation.NSString)
M:ScreenTime.STWebHistory.DeleteAllHistory
M:ScreenTime.STWebHistory.DeleteHistory(Foundation.NSDateInterval)
M:ScreenTime.STWebHistory.DeleteHistory(Foundation.NSUrl)
M:ScreenTime.STWebHistory.FetchHistory(Foundation.NSDateInterval,ScreenTime.STWebHistoryFetchHistoryCallback)
M:ScreenTime.STWebHistory.FetchHistory(ScreenTime.STWebHistoryFetchHistoryCallback)
M:ScreenTime.STWebHistory.FetchHistoryAsync
M:ScreenTime.STWebHistory.FetchHistoryAsync(Foundation.NSDateInterval)
M:ScreenTime.STWebpageController.#ctor(System.String,Foundation.NSBundle)
M:ScreenTime.STWebpageController.SetBundleIdentifier(System.String,Foundation.NSError@)
M:ScriptingBridge.ISBApplicationDelegate.EventFailed(System.IntPtr,Foundation.NSError)
Expand Down Expand Up @@ -55803,6 +55807,7 @@ P:ScreenCaptureKit.SCWindow.Active
P:ScreenCaptureKit.SCWindow.OnScreen
P:ScreenTime.STScreenTimeConfiguration.EnforcesChildRestrictions
P:ScreenTime.STScreenTimeConfigurationObserver.Configuration
P:ScreenTime.STWebpageController.ProfileIdentifier
P:ScreenTime.STWebpageController.SuppressUsageRecording
P:ScreenTime.STWebpageController.Url
P:ScreenTime.STWebpageController.UrlIsBlocked
Expand Down Expand Up @@ -66856,6 +66861,7 @@ T:ScreenCaptureKit.SCStreamType
T:ScreenTime.STScreenTimeConfiguration
T:ScreenTime.STScreenTimeConfigurationObserver
T:ScreenTime.STWebHistory
T:ScreenTime.STWebHistoryFetchHistoryCallback
T:ScreenTime.STWebpageController
T:ScriptingBridge.AESendMode
T:ScriptingBridge.ISBApplicationDelegate
Expand Down
45 changes: 45 additions & 0 deletions tests/monotouch-test/ScreenTime/STWebHistoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Unit tests for STWebHistory
//
// Authors:
// Rolf Bjarne Kvinge <[email protected]>
//
// Copyright 2025 Microsoft Corp. All rights reserved.
//

#if HAS_SCREENTIME

using System;

using Foundation;
using ScreenTime;

using NUnit.Framework;

namespace MonoTouchFixtures.ScreenTime {

[TestFixture]
[Preserve (AllMembers = true)]
public class STWebHistoryTest {

[Test]
public void Create_WithBundleIdentifier ()
{
TestRuntime.AssertXcodeVersion (16, 3);
using var obj = STWebHistory.Create ("com.xamarin.monotouch-test", out var error);
Assert.IsNotNull (obj, "Object");
Assert.IsNull (error, "Error");
}

[Test]
public void Create_WithBundleIdentifierAndProfile ()
{
TestRuntime.AssertXcodeVersion (16, 3);
using var obj = STWebHistory.Create ("com.xamarin.monotouch-test", (NSString) "profile", out var error);
Assert.IsNotNull (obj, "Object");
Assert.IsNull (error, "Error");
}
}
}

#endif

This file was deleted.

6 changes: 0 additions & 6 deletions tests/xtro-sharpie/api-annotations-dotnet/iOS-ScreenTime.todo

This file was deleted.

This file was deleted.

Loading