Privacy redaction not working in iOS16 beta widget

I tried to use privacySensitive and redactionReasons to show different view in widget, but I notice that this is not working on iOS 16 beta (5~7)

Below is my test code, if I use Xcode 13.4.1 with iOS 15 it works properly, in Lock Screen lock state it will display placeholder and "Privacy", but in iOS 16 not (in systemSmall widget).

I'm trying use this privacy feature in new lockscreen widget (it doesn't work in new widget as well), does any one know how to fix this issue?

struct WidgetEntryView : View {

    var entry: Provider.Entry

    @Environment(\.redactionReasons) var redactionReasons

    var body: some View {

        Text(entry.date, style: .time)

            .privacySensitive()

        if redactionReasons.contains(.privacy) {

            Text("Privacy")

        } else {

            Text("Not Privacy")

        }

    }

}

Xcode : Xcode 14 beta 6

iOS: iOS 16 beta 7

If you haven't got this working, try this...

Add this extension somewhere:

extension View {
	/// Applies a modifier to a view conditionally.
	///
	/// - Parameters:
	///   - condition: The condition to determine if the content should be applied.
	///   - content: The modifier to apply to the view.
	/// - Returns: The modified view.
	@ViewBuilder func modifier<T: View>(
		if condition: @autoclosure () -> Bool,
		then content: (Self) -> T
	) -> some View {
		if condition() {
			content(self)
		} else {
			self
		}
	}

	/// Applies a modifier to a view conditionally.
	///
	/// - Parameters:
	///   - condition: The condition to determine the content to be applied.
	///   - trueContent: The modifier to apply to the view if the condition passes.
	///   - falseContent: The modifier to apply to the view if the condition fails.
	/// - Returns: The modified view.
	@ViewBuilder func modifier<TrueContent: View, FalseContent: View>(
		if condition: @autoclosure () -> Bool,
		then trueContent: (Self) -> TrueContent,
		else falseContent: (Self) -> FalseContent
	) -> some View {
		if condition() {
			trueContent(self)
		} else {
			falseContent(self)
		}
	}
}

Create a little helper function somewhere that saves you a bunch of typing. Pass in your redactionReasons variable:

func getHideInfo(_ redactionReasons: RedactionReasons) -> Bool {
	return (redactionReasons.contains(.privacy) || redactionReasons.contains(.placeholder))
}

In your view body, add this line:

let hideInfo: Bool = getHideInfo(redactionReasons)

i.e.:

var body: some View {
	let hideInfo: Bool = getHideInfo(redactionReasons)
  ...
}

Then, on your views, Text(), Image() etc. add this;

.modifier(if: hideInfo) { $0.redacted(reason: .placeholder) } else: { $0.unredacted() }

i.e.:

Text("Hello World!")
  .modifier(if: hideInfo) { $0.redacted(reason: .placeholder) } else: { $0.unredacted() }

What that does is redact the view if it's meant to be private, and unredact it if not. It's pretty easy having that one modifier on a view.

Remember to use the different controls on the preview canvas in Xcode to see the "Presentation" variants. It will show you what your widget looks like normally, privacy sensitive, placeholder and luminance reduced.

Hope this helps.

We are also facing this issue. Have you found any solution?

@MohammedIdhiris None so far, I guess Apple totally forgot this issue lol

I am having a lot of trouble with this. My idea was going to be to put a switch in the setting page of my app so user can choose if they want sensitive information redacted or not. Some people may want to hide their appointment on the Lock Screen, others may not.

redacted(reason: .placeholder)

works fine. but the .privacy reason docent seam to work. If I add the capability to the target 'Data Protection' every thing on the widget gets redacted, unless I mark elements with .unredacted() But to have to do that for everything is too difficult.

My thinking around how it worked was to add the modifier, redacted(reason: .privacy) to an element like a Text view or an image and if the device is locked that will be redacted. I must not have the same thinking as Apple on this process.

I have the same problem. I believe this is iOS16 bug as Apple calendar app still not get redacted...

Privacy redaction not working in iOS16 beta widget
 
 
Q