How can you use iOS UIAutomation to see if the application badge is correct? - ios-ui-automation

Like many apps, we badge the application to indicate $SOMETHING. How can we use UIAutomation to check that the badge is correct? The problem, of course, is that UIAutomation gives you lots of ways to interact with your application, but the badge is outside the app. (Note that I'm not talking about badges on tab bars; I'm talking about badges on the application icon.)

Related

Does Earlgrey for iOS support UI elements outside of the test app?

I am totally new to iOS, Xcode and automated test frameworks.
I would like to confirm 3 things about iOS testing using EarlGrey:
It cannot access elements outside of the test app. For example, the test app cannot press the 'HOME' key
It does not support the 'swipe up' gesture to bring up the control centre
It cannot not put a test app in background and then bring it to the foreground
If I understand correctly, EarlGrey only allows control of the UI elements defined inside the test app.
Is this correct?
Thanks
Yup, you are right but Out-of-app interaction is being worked on please follow along here.

How can I detect/observe when third party app launches a full screen process?

I would like to build a helper app for gamers, and to build some extra functionality I would like to observe/time certain third party games behaviors, more specifically when the game actually launches the full screen process.
For example: my app is a system tray app, the game has a "launcher" app with lobby and menu screens. Once the game launches the extra process, usually OS X will switch resolutions (optionally) and my App would be notified somehow. Then I can start a timer. Once game match finishes, either the process is closed, or the game is not full screen anymore, my app gets a second notification and I can stop the timer.
Are there official Apple APIs that provide any way to observe/poll for the app going full screen and/or launch additional windows that I can reliably assume it's the actual game screen?
I doubt you're going to find a completely comprehensive solution. There are many ways for apps to achieve a full-screen experience and most don't provide a notification about that fact.
A full-screen app can modify the presentationOptions of NSApplication to hide the Dock and menu bar. Another app can use key-value observing to monitor its application object's currentSystemPresentationOptions property, which will reflect the current system status.
A full-screen app can capture the displays (although Apple discourages this technique). You can try to detect this by calling CGDisplayIsCaptured(), although it's been deprecated since 10.9 with no replacement. It may be possible that, if you register a callback with CGDisplayRegisterReconfigurationCallback(), you'll get called when something captures the display. However, capturing the display is sort of about preventing other processes from noticing such changes, so maybe not. In that case, you'd have to poll. You might also poll for the current display mode; changing the mode is the primary reason why a game would capture the display in the first place.
A full-screen game could also just create a borderless window the size of the screen and set its window level to be in front of the Dock and menu bar (and other apps' windows). There's not really a notification about this. You could detect it using the CGWindowList API, but you would have to poll. For example, you could call CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID) and iterate through the dictionaries looking for one the size of the screen and at a window level above kCGStatusWindowLevel.
(You might be able to use the Accessibility API to get a notification when the frontmost window changes, so you'd only have to poll when that happens.)
You cannot observe a notification if there is none. So firstly you need to know if the app you want to observe is actually sending a notification that is observable. You cannot 'hook' into other apps without their planned consent.

How to implement a Facebook like button without leaving iOS app?

I was wondering how can I implement a Facebook "Like" and "Unlike" button right within my app without making the user leave the app. I know Apple has implemented this in their App Store app, so it is clearly possible. Here are some screenshots:
Notice how you can press the like and unlike buttons and you remain in the App Store application. I would like to link these like buttons to my Facebook page.

How do you hide the menu bar in a Cocoa app?

How do you programmatically hide the menu bar in a cocoa app? I would like to make full use of the screen area.
There are two good ways I know of to do this.
1
In Cocoa, you can call the NSMenu class method setMenuBarVisible: to show or hide the menu bar.
As of this writing, the documentation for the NSMenu class does not tell you the following additional information.
The menu bar will only be hidden for the app that calls this method.
The Dock will also be hidden at the same time.
(This is true at least in 10.9 and I have not tested any other versions.)
This is useful when you want to use an app in a full screen way where you have a cover window, a borderless window the size of the screen.
The nice feature of this (as opposed to playing with LSUIElement settings) is that your app can continue to be in the application switcher cycling, as well as visible in the Dock when other apps are active.
This allows users to still activate a full screen app through the Dock or application switcher.
That means you can still use your app's Dock menu to access a preferences window for your app or other features.
This is incredibly convenient if your app is indeed a full screen cover window that runs at a window level higher than other apps, but you still want to make preferences and the ability to quit your app available, and you want your app's visual functionality available when other apps are active.
2
Another option is via NSApplication's method setPresentationOptions: with the arguments from NSApplicationPresentationOptions enum, such as option NSApplicationPresentationHideMenuBar
With this approach be very wary of reading the documentation, although it gives you additional options, and is still app-specific only, you need to know that some of the options are mutually exclusive. There are rules you must follow, or you get nothing but exceptions spewed to the console.
3 There is a 3rd and crappy option. If you have a helper app that is a daemon, you can use it to change your app's LSUIElement state and basically relaunch your app. It's dumb and it takes you out of the app switcher completely, which is great if you really are writing something that should not be there, but that is rare.
There is also the NSView enterFullScreenMode:withOptions: method, although most apps for which that would be appropriate prior to 10.7 should probably use the modern full-screen-window API on 10.7 and later.

Cocoa Touch how to design the interface like facebook iPhone application's home screen?

I am just curious how facebook for iPhone application can display a list of icons with the text, then all the icons shake to allow user to change the position of each item.
What kind of control is that, and is there some sample code that do the same thing?
I think it must be standard because it exists as well in home screen of iPhone and iPod app to choose the tab item.
Thank you.
It's not a standard control. It's generally implemented with Core Animation and a rotation transform.
Apple discourages App developers from imitating the spring board, claiming it is confusing for the user. So don't expect standard controls for this.
You can of course implement it yourself with animation. Basic (property based) animation should be sufficient.