Apple watch event detection - event-handling

Are anybody aware of any event api for the apple watch ? I'm looking for detecting events like on/off wrist events do determine if glances should be displayed or not.

There are not any events other than the simple ones declared in the various interface controls, like willActivate, didDeactivate, button taps, etc..
There are rumors that the next version of WatchKit this Fall will include more capabilities like being able to run some code on the watch itself, so maybe it'll be possible to have more event notifications once that comes out, but who knows.

Related

Inject system wide touch events on iOS7

Prior to iOS7 it was possible to inject touch events with the GSSendSystemEvent and GSSendEvent private API calls, eg:
GSSendEvent - Inject Touch Event iOS
Simulating System Wide Touch Events on iOS
System-wide tap simulation on iOS
Send a global touch event on iOS 6
On iOS7 these calls seem to silently fail though. An alternative has been suggested in Simulating system-wide touches in iOS 7 but it only works on jailbroken devices. https://github.com/kif-framework/KIF looks like another option, but it appears that it only supports injecting events for the current app rather than system wide (so you couldn't inject a touch event while you're app is in the background, for example).
So how can you inject system wide touch events on iOS7, without a jailbreak?
I assume you need to do this system-wide for a testing scenario? In which case you might be well served by Apple's UI Automation framework, a JavaScript-based tool useful for on-device testing.
While you can't do things like simulate a home-button press, you can send your app to the background for a specified duration, for example:
UIATarget.localTarget().deactivateAppForDuration(seconds);
Here are the docs:
https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef
You can subclass UIWindow and overwrite sendEvent. I use it to implement a multiple listeners pattern, but you can also use it to fire events...
- (void)sendEvent:(UIEvent*)event {
[super sendEvent:event];
//NSLog(#"NSEventListenerWindow.sentEvent: %#\n", event);
// pass all events on to those who listen
for ( id listener in listeners) {
if ([listener respondsToSelector:#selector(sendEvent:)]) {
[listener sendEvent:event];
}
}
.....
I think you'd be better off using iOS SDK Notification service api. That would be the cleanest way to achieve what you want.
Conceptually, Apple doesn't (yet) intend third-parties to issue system wide events since that wouldn't sit well with iOS careful curating model, that's why people resort to private APIs and jailbreaking. Private APIs, as the name implies, are not supposed to be relied upon.
Think about it this way, unless you were responsible for the whole system, which a user app couldn't possibly be, you really have no business generating system wide events. I know how Android does this, but that's another story (not fit for this topic).
On the Mac, the XPC Services api for allows processes to communicate with one another, still not quite a method for generating system wide event. I'd suggest you use iOS SDK's notification API, that would probably be the cleanest method to achieve what you want. Yes, it goes out to Apple and back to the device, but that's the mechanism that is available up to now.

processing touch events as mouse events in Android apps

I've tried looking for similar posts but looks like they are all for the browser. I'm running JellyBean and don't have a touch device, so some apps (such as SubwaySurfer) don't respond. Is there a way to use mouse events instead? Would truly appreciate any help
Is the app supposed to take care of this? Or can it be done somewhere within Android?

Getting notification of iOS device usage in background

Might be i am using a wrong title but i will try to explain here what i want.
In iOS i need to implement a functionality to get notify if the user is using their iOS device.
My app will be running in background using location services and i need to find out if the the user is using their device. It is doable as i have looked into this application which is sending notifications in background to the drivers who is suing their devices while driving.
https://itunes.apple.com/fr/app/cellcontrol/id661169580?l=en&mt=8&ign-mpt=uo=2
So i need similar kind of functionality to find out if a user is using iOS device or not. If anyone of you can suggest me any approach then it would be great for me to start.
Thank you!
Note: I have tried to find out touch events in background but that is not possible as i have done some research on this.
You won't be able to receive touch events when the app is in background using public API's. However, you can do that with the help of mobileSubstrate library ( http://iphonedevwiki.net/index.php/MobileSubstrate - The MobileHooker component is the one that would be used). by hooking your process to the OS. As an example, the display recorder app in Cydia tracks global gestures while recording the screen. This will be a cydia tweak and you will need to jailbreak your device to do all that.
Coming to your specific use-case, the example app you cited should be using one of the exceptions for background applications mentioned in https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html (see the section - "Implementing Long-Running Background Tasks"), probably the one to receive updates from external accessories.

How to implement an alarm with iPhone SDK 4.0

I have an idea for a pretty unusual alarm clock fir the iPhone. But as of now I have some thoughts on how to actually implement this. First off: forgetting about background services for now, how would I do the actual timer that fires the alarm etc? A separate thread? Or does the SDK include any nice alarm features I missed? Of cause I need to be as battery efficient as possible. But for now I do no background process.
Please advise me on this as it is a crucial concept of this app, if it will work or not.
I would create a local notification. Compared to NSTimer, local notifications have the advantage that they work regardless of whether your app is running or not.
You must create a UILocalNotification object and schedule it with scheduleLocalNotification, it is quite simple but there are strong limitations. You app may or may not be notified that the alarm occurred. When the alarm is presented, it will be in form of a AlertView. If the user taps "Close" you do not get a notification. If he taps "View Details", then you get the event didReceiveLocalNotification, your app moves to the foreground and can do whatever you want.
You can also register with iOS4 to receive updates on location change. The parsing of XML can be done but again there are limitations as to how much time you have to run methods in the background.
All information along with sample code can be found here: http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

iPhone headphone click detection

I've tried looking through the documentation, but I can't seem to find (or recognize) what I'm looking for.
The iPhone and iPod Touch have a momentary switch on the headphones, which I believe is called the "remote" (please correct me if I'm wrong). It is used to start/stop/forward/back for music or to pickup/end a phone call. I'd like to know when this switch is clicked in my native application.
In which framework and classes would I find this?
I don't believe this functionality is supported by any current framework.
If your application has iPod playback during execution you could register for MPMusicPlayerController notifications - Music Player Notifications
This will notify you of the playback state changes you mention above. However, it will not tell you whether the state was changed via the remote or the UI. But it's the only way that I know of to 'guess' if the remote button was clicked - I use this method in one of my own apps.