Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23891] iOS 10: Support iPhone 7 Haptic Engine API

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-10-06T08:25:50.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.0.0
ComponentsiOS
Labelsios, ios10, qe-6.0.0
ReporterDonovan Lewis
AssigneeHans Knöchel
Created2016-09-09T23:48:28.000+0000
Updated2018-10-20T09:28:50.000+0000

Description

iOS 10 exposes new API's for the iPhone 7 for generating feedback when an action happens through a new Haptic Engine API and UIFeedbackGenerator. This would be great to be exposed for all Ti users. https://developer.apple.com/ios/human-interface-guidelines/interaction/feedback/ https://www.hackingwithswift.com/example-code/uikit/how-to-generate-haptic-feedback-with-uifeedbackgenerator

Comments

  1. Hans Knöchel 2016-09-10

    Thanks for the ticket! I searched for the correct API's yesterday but couldn't find them. It seems like it is all about the UIFeedbackGenerator subclasses, am I correct? There not seem to be any docs about that, yet.
  2. Hans Knöchel 2016-09-10

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/8342 PR (6_0_X: https://github.com/appcelerator/titanium_mobile/pull/8389 Demo:
       var dataStructure = [
       	"FEEDBACK_GENERATOR_TYPE_SELECTION",
       	"FEEDBACK_GENERATOR_TYPE_IMPACT",
       	"FEEDBACK_GENERATOR_TYPE_NOTIFICATION",
       ];
       
       var win = Ti.UI.createWindow({
           backgroundColor: "#fff",
       	title: "iOS 10 Haptic Engine",
       	translucent: false
       });
       
       var nav = Ti.UI.iOS.createNavigationWindow({
       	window: win
       });
       
       var list = Ti.UI.createListView({
       	sections: [
       		Ti.UI.createListSection({
       			items: createItems()
       		})
       	]
       });
       
       list.addEventListener("itemclick", function(e) {
       	var type = e.itemId;
       	var args = {
       		type: Ti.UI.iOS[type] // Same as Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_SELECTION etc.
       	};
       
       	// If we select the impact-feedback, the style property specifies the style of it
       	if (Ti.UI.iOS[type] == Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_IMPACT) {
       		args["style"] = Ti.UI.iOS.FEEDBACK_GENERATOR_IMPACT_STYLE_MEDIUM;
       	}
       
       	// Create the generator with the selected type
       	var generator = Ti.UI.iOS.createFeedbackGenerator(args);
       	generator.prepare(); // Prepare the feedback before to avoid latence
       
       	// Execute different feedbacks based on the type
       	switch (generator.type) {
       		case Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_SELECTION:
       			generator.selectionChanged();
       		break;
       		case Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_IMPACT:
       			generator.impactOccurred();
       		break;
       		case Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_NOTIFICATION:
       			generator.notificationOccurred(Ti.UI.iOS.FEEDBACK_GENERATOR_NOTIFICATION_TYPE_SUCCESS);
       		break;
       	}
       
       	this.deselectItem(e.sectionIndex, e.itemIndex);
       });
       
       win.add(list);
       nav.open();
       
       function createItems() {
       	var items = [];
       
       	for (var i = 0; i < dataStructure.length; i++) {
       		items.push({
       			properties: {
       				itemId: dataStructure[i],
       				title: dataStructure[i],
       				height: 60,
       				accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE
       			}
       		});
       	}
       
       	return items;
       }
       
  3. Donovan Lewis 2016-09-10

    The only other documentation I have been able to find on it is: https://developer.apple.com/ios/human-interface-guidelines/interaction/feedback/ The hackingwithswift article was the only thing I could find with some bit of how it works. Apple says it needs to be Prepared but there isn't much right now on how to work with this thing. I looks like UINotificationFeedbackGenerator is the most important. Thanks for adding this to TI.
  4. Hans Knöchel 2016-09-10

    [~cng] to review this PR. Since we are *very* early with this PR and the iPhone 7 is not even out, yet, testing can be done through debugging debugging the methods-calls through Xcode as I did.
  5. Scott Davenport 2016-09-13

    Sorry for the delay here...I really like the idea of supporting this capability. I agree with the Hyperloop statement and that would be ideal but Han's point is key as to who can have access to this without us exposing it directly.
  6. Hans Knöchel 2016-09-16

    Just tested the API on a real iPhone 7 device. Works without further adjustments!
  7. Donovan Lewis 2016-09-17

    I tried to get this to work on my iPhone 7 but was unable to. I can get it to work in the simulator but on device it will throw errors. On device using the same code provided I get "undefined is not a function (evaluating 'Ti.UI.iOS.createFeedbackGenerator(i)') at app.js (line 1)" I'm sure it works, I tried adding it into a build of 6.0.x and 6.1.x I have have done something wrong there but can't see anything I did going over it so hopefully just a mistake I made somewhere.
  8. Hans Knöchel 2016-09-17

    [~dlewis23] That's because it's status is In Review meaning that it is not merged, yet.
  9. Chee Kiat Ng 2016-10-06

    CR AND FT PASSED. Tested with sample code and the following constants: Ti.UI.iOS.FEEDBACK_GENERATOR_NOTIFICATION_TYPE_ERROR Ti.UI.iOS.FEEDBACK_GENERATOR_NOTIFICATION_TYPE_WARNING Ti.UI.iOS.FEEDBACK_GENERATOR_NOTIFICATION_TYPE_SUCCESS Ti.UI.iOS.FEEDBACK_GENERATOR_IMPACT_STYLE_LIGHT Ti.UI.iOS.FEEDBACK_GENERATOR_IMPACT_STYLE_MEDIUM Ti.UI.iOS.FEEDBACK_GENERATOR_IMPACT_STYLE_HEAVY
  10. Harry Bryant 2016-11-02

    I can report that I am experiencing the same behaviour as [~dlewis23] has described. Using the provided sample code and running to an iPhone 7 Device, I see the following error when selecting any of the FEEDBACK_GENERATOR_TYPES:
        [ERROR] :  Script Error {
        [ERROR] :      column = 804;
        [ERROR] :      line = 1;
        [ERROR] :      message = "undefined is not a function (evaluating 'Ti.UI.iOS.createFeedbackGenerator(t)')";
        [ERROR] :      sourceURL = "file:///var/containers/Bundle/Application/3B45FD55-0EF0-4AAE-86A0-1C59EC2A25DB/HapticTest.app/app.js";
        [ERROR] :      stack = "file:///var/containers/Bundle/Application/3B45FD55-0EF0-4AAE-86A0-1C59EC2A25DB/HapticTest.app/app.js:1:804";
        [ERROR] :  }
        
    This does not occur on simulator. Checked that selected SDK 6.0.0.v20161101155110 had the merged files present. Tested On: iPhone 7 10.0.3 Device & Simulator Mac OS Sierra (10.12) Ti SDK: 6.0.0.v20161101155110 Appc Studio: 4.8.0.201610060953 Appc NPM: 4.2.8-9 App CLI: 6.0.0-68 Xcode 8.0 Node v4.4.7
  11. Hans Knöchel 2016-11-02

    Fixed the device-issue in [#8576](https://github.com/appcelerator/titanium_mobile/pull/8576) and [#8577](https://github.com/appcelerator/titanium_mobile/pull/8577), thx!
  12. Harry Bryant 2016-11-03

    Verified as fixed, tested the various available constants and can confirm that they work without issue Tested On: iPhone 7 10.1.1 Device & Simulator Mac OS Sierra (10.12.1) Ti SDK: 6.0.0.v20161102104808 Appc Studio: 4.8.0.201610060953 Appc NPM: 4.2.8-9 App CLI: 6.0.0-68 Xcode 8.1 Node v4.4.7 *Closing ticket.*
  13. Andrea Vitale 2018-10-20

    Hi guys, I'm trying to use this feature on an iPhone 7 with iOS 11.4.1 and the latest Ti SDK 7.4.1.GA with this code:
               if (OS_IOS) {
                    var hapticFeedbackGenerator = Ti.UI.iOS.createFeedbackGenerator({
                        type: Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_SELECTION
                    });
        
                    hapticFeedbackGenerator.prepare();
                    hapticFeedbackGenerator.selectionChanged();
                }
        
    I got the same error as reported in this issue:
        [ERROR] Script Error {
        [ERROR]     column = 72;
        [ERROR]     line = 197;
        [ERROR]     message = "Ti.UI.iOS.createFeedbackGenerator is not a function. (In 'Ti.UI.iOS.createFeedbackGenerator({\n          type: Ti.UI.iOS.FEEDBACK_GENERATOR_TYPE_SELECTION })', 'Ti.UI.iOS.createFeedbackGenerator' is undefined)";
        [ERROR]     stack = "    at onLoginWithEmail)\n    at trigger)\n    at onButtonClick)";
        [ERROR] } 
        

JSON Source