0

An object that helps a user share data from one place to another within your app, and from your app to other apps.

This is the statement written at the very beginning of UIPasteboard docs. But when I try to use it in two different apps accessing data set by other app I am getting nil everytime

 DispatchQueue.global(qos: .background).async {
    var i = 1
    while(i > 0) {
         let v = UIPasteboard.general.string
         sleep(1)
         print("Task : \(i)")
         print("Value: \(v)")
         i = i + 1
    }
  }

I am fetching data in above code and setting data as in below code.

UIPasteboard.general.string = "Hello"

NB: I have tested locally in this app it is setting data

Angel F Syrus
  • 1,984
  • 8
  • 23
  • 43
Thullo
  • 97
  • 15

1 Answers1

0

Are you running iOS >=10? There was a privacy change regarding passing value between apps. Try reading the UIPasteBoard api doc : (https://developer.apple.com/documentation/uikit/uipasteboard).

Tl:dr You need to have both apps to be in the same app group (Communicating and persisting data between apps with App Groups)

To note: iOS apps are sandboxed. So the change in iOS 10 just enforces that feature.

EDITED: Since you can't use App Groups (different developer and/or products), you have to send data via a different channel. Try searching urlSchemes or store/fetch through a common server(tedious tho)

  • It is saying we should use app groups but the problem with app groups is One of the two app is third party app who will be implementing our library so as far I have search I believe it is not possible to use app groups for app and framework. And yes target ios is above 10 – Thullo May 24 '19 at 07:52
  • Then you can't use UIPasteboard to transfer data. How about using urlSchemes or going through a server? – Joshua Francis Roman May 24 '19 at 07:55
  • isn't there anything that is available for all apps to access other than doc picker things?? – Thullo May 24 '19 at 08:29