0

We are trying to control out pasteboard contents for our application. I have seen the way to create a custom text field and remove the ability that way, but I'm inquiring to find if there is a way to do it at the app level.

I was trying to utilize applicationWillResignActive, applicationDidenterBackground, and applicationWillTerminate. With those I figure I can clear the pasteboard contents and then have that data safe outside the app.

My initial attempt was to emulate something I had seen from a previous solution that may no longer work.

var pb = self.pasteboard()
pb.setValue("", forPasteboardType: UIPasteboardNameGeneral)

The error here being that the AppDelegate has no member pasteboard

Is there a way to make it work in app delegate, or am I relegated to changing all the fields in the app?

comrade
  • 4,590
  • 5
  • 33
  • 48
James Cockerham
  • 399
  • 1
  • 3
  • 13

2 Answers2

0

There is no self.pasteboard(), but there is UIPasteboard.generalPasteboard().

Use that instead.

David Ganster
  • 1,985
  • 1
  • 18
  • 26
0

You might have seen the previous answers where self.pasteboard() returns an instance of UIPasteboard and now in your application it is not handled. So you just try this:

let pasteBoard = UIPasteboard()
pasteBoard.setValue("", forPasteboardType: UIPasteboardNameGeneral)

Or if you want to get the pasteBoard instance in all other methods then just declare a lazy var in your appDelegate:

lazy var pasteBoard = UIPasteboard()

Then use it in any methods like below:

self.pasteBoard.setValue("", forPasteboardType: UIPasteboardNameGeneral)
Santosh
  • 2,900
  • 1
  • 16
  • 16