How can we get text while user copying message from whats up , Skype and so on like third party app using iOS Swift?

273 Views Asked by At

Step 01: I can run my app (APP NAME : TextDetectAPP)

Step 02: User press Home button

Step 03:User open the Skype or any third party app (APP NAME : TextDetectAPPMove to Background state )

Spep04: User copy text (I need to get copy text from Skype or or any third party app )

Note :

  • UIpasteboard is working fine only user developed apps in iOS swift

  • Shall we have access rights to read text messages from Skype , whats up or any thirds parts apps in iOS swift?

Thanks in Advance

1

There are 1 best solutions below

4
badhanganesh On

If I understand your question right, you want to get texts that were copied in other apps (Skype, FB etc.). You can do this using the UIPasteboard class. Usually texts are copied to the general pasteboard and you can access it without any problems (I've tried with Skype and Message (iOS) applications, it is working). When you open your app back, you can get the copied text from third party apps like this in the applicationDidBecomeActive delegate method:

func applicationDidBecomeActive(_ application: UIApplication) {
    if let clipboardString = UIPasteboard.general.string {
        print(clipboardString)
    }
}

You can also use UIPasteboardChanged notification to listen to changes in pasteboard, however you cannot receive change notifications from other apps. Also your app may not be in background state all the time executing code (unless you enable some specific background modes like Audio, Airplay etc.). So there is no way for you to get the copied texts when you are in background. You either need to use the method above, (or) if your app supports background execution, you can have an NSTimer fire every n seconds that gets the pasteboard content.