Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to find a robust way to check if an app was downloaded via MDM and is available on the device. I would think the below would work:

let authenticatorApp = XCUIApplication(bundleIdentifier: "com.microsoft.azureauthenticator")
XCTAssert(authenticatorApp.waitForExistence(timeout: 60))

However this seems to always time out, even if the app is installed.

The only way I can think of requires checking the existence of an URL scheme, but I don't think that would work with all apps since some don't have one.

Is there any better way?

UPDATE: I tried do-catch of launch(), but it seems it doesn't throw an exception and always fails the test, so this won't work. Also I tried watching the state in a for-loop (with a sleep) but that didn't work either.

UPDATE2: I am not even able to get this working with the canOpenURL() route. I get "This app is not allowed to query" even when I add an entry in the "LSApplicationQueriesSchemes", and I heard this broke on some version of iOS (13?)

question from:https://stackoverflow.com/questions/66065409/checking-for-app-installation-in-xcuitest

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
240 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can check for URL scheme with canOpenURL: function. But remember! you can't check for a dynamic list of schemes! Because from iOS 9+ you must whitelist any URL schemes your App wants to query in Info.plist under the LSApplicationQueriesSchemes key (an array of strings):

preview

The reason of this limitation is to restrict apps to track user's installed apps and the AppStoreConnect may ask you why you think you want to open all these schemes in the review process.

Check Asynchronously

Also you can use open:options:completionHandler: method and check inside the completionHandler. This method is more likely to be a successful try in iOS 14 but don't forget that it is an async task!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...