-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-19708, TIMOB-19709, TIMOB-19710, TIMOB-19711, TIMOB-19712, TIMOB-19713, TIMOB-19714, TIMOB-19715] Fix and improve UIApplicationShortcuts #7290
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ description: | | |
app-specific actions from the Home screen by pressing on the app icon. The pressing of an application shortcut | ||
will then fire the `shortcutitemclick` Titanium.App.iOS event. | ||
|
||
To use this feature make sure you have a 3D Touch compatible device running iOS 9 or later. | ||
To use this feature make sure you have a 3D Touch compatible device running iOS 9 or later. You can check | ||
this by using the <Titanium.UI.iOS.forceTouchSupported> property. | ||
extends: Titanium.Proxy | ||
platforms: [iphone] | ||
osver: {ios: {min: "9.0"}} | ||
|
@@ -30,112 +31,169 @@ methods: | |
- name: dynamicShortcutExists | ||
summary: Returns true or false depending if the provided shortcut dictionary already exists. | ||
parameters: | ||
- name: params | ||
summary: | | ||
The parameters used when creating the dynamic shortcut. Must include a `type` property, | ||
to determine if the shortcut exists. | ||
type: Dictionary | ||
- name: itemtype | ||
summary: Checks if the dynamic application shortcut item identified by the `itemtype` exists. | ||
type: String | ||
returns: | ||
type: Boolean | ||
|
||
- name: addShortcutItem | ||
summary: Creates a dynamic application shortcut. | ||
- name: addDynamicShortcut | ||
summary: Creates a new dynamic application shortcut item. | ||
parameters: | ||
- name: params | ||
summary: The parameters used when creating a dynamic shortcut. | ||
type: ShortcutParams | ||
|
||
- name: removeDynamicShortcut | ||
summary: Removes the dynamic application shortcut item identified by the `itemtype`. | ||
parameters: | ||
- name: itemtype | ||
summary: | | ||
The parameters used when creating the dynamic shortcut. Must include the `type` and `title` properties. | ||
Properties are: | ||
* type - the unique key for the application shortcut | ||
* title - the title of the application shortcut | ||
* subtitle - the subtitle displayed on the application shortcut | ||
* icon - the icon to be displayed on the application shortcut, for example Titanium.UI.iOS.SHORTCUT_ICON_TYPE_COMPOSE | ||
type: Dictionary | ||
|
||
- name: removeShortcutItem | ||
summary: Removes the provided application shortcut item. | ||
Use the `itemtype` property to determine which shortcut should be removed. | ||
type: String | ||
|
||
- name: getDynamicShortcut | ||
summary: Gets the dynamic application shortcut item identified by the `itemtype`. | ||
parameters: | ||
- name: params | ||
- name: itemtype | ||
summary: | | ||
The parameters used when creating the dynamic shortcut. Must include a `type` property, | ||
to determine which shortcut should be removed. | ||
type: Dictionary | ||
Use the `itemtype` property to determine which shortcut should be returned. | ||
type: String | ||
|
||
examples: | ||
examples: | ||
- title: Example app.js | ||
example: | | ||
The following code excerpt demonstrates | ||
|
||
var win = Titanium.UI.createWindow({ | ||
title:'Example', backgroundColor:'#fff', layout:"vertical" | ||
Ti.App.addEventListener("resume", function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the resume and resumed here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For debug, will remove that lines. |
||
Ti.API.info("Resume Event Fired"); | ||
}); | ||
|
||
Ti.App.addEventListener("resumed", function(){ | ||
Ti.API.info("Resumed Event Fired"); | ||
}); | ||
|
||
Ti.App.iOS.addEventListener("shortcutitemclick", function(e){ | ||
Ti.API.info("shortcutitemclick Event Fired"); | ||
Ti.API.info("event payload:" + JSON.stringify(e)); | ||
}); | ||
|
||
var win = Titanium.UI.createWindow({ | ||
title:'Test', backgroundColor:'#fff', layout:"vertical" | ||
}); | ||
|
||
var btn1 = Ti.UI.createButton({ | ||
top: 50, height:45, title:"Add Contact Us Application Shortcut" | ||
top: 50, height:45, title:"Add Contact Us Application Shortcut" | ||
}); | ||
win.add(btn1); | ||
|
||
btn1.addEventListener("click",function(){ | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
appShortcuts.addShortcutItem({ | ||
type:"contact_us", | ||
title:"Contact Us", | ||
subtitle:"Tap to reach us", | ||
icon: Ti.UI.iOS.SHORTCUT_ICON_TYPE_ADD, | ||
userInfo:{ | ||
infoKey:"contact_us" | ||
} | ||
}); | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
appShortcuts.addDynamicShortcut({ | ||
itemtype:"contact_us", | ||
title:"Contact Us", | ||
subtitle:"Tap to reach us", | ||
icon: Ti.UI.iOS.SHORTCUT_ICON_TYPE_ADD, | ||
userInfo:{ | ||
infoKey:"contact_us" | ||
} | ||
}); | ||
}); | ||
|
||
var btn2 = Ti.UI.createButton({ | ||
top: 10, height:45, title:"Remove Contact Us Application Shortcut" | ||
top: 10, height:45, title:"Remove Contact Us Application Shortcut" | ||
}); | ||
win.add(btn2); | ||
|
||
btn2.addEventListener("click",function(){ | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
appShortcuts.removeShortcutItem({ | ||
type:"contact_us" | ||
}); | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
appShortcuts.removeDynamicShortcut("contact_us"); | ||
}); | ||
|
||
var btn3 = Ti.UI.createButton({ | ||
top: 10, height:45, title:"Count Dynamic App Shortcuts" | ||
top: 10, height:45, title:"Count Dynamic App Shortcuts" | ||
}); | ||
win.add(btn3); | ||
|
||
btn3.addEventListener("click",function(){ | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
var shortcutItems = appShortcuts.listDynamicShortcuts(); | ||
Ti.API.info("Dynamic App Shortcut as JSON:" + JSON.stringify(shortcutItems)); | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
var shortcuts = appShortcuts.listDynamicShortcuts(); | ||
Ti.API.info("Dynamic App Shortcut count:" + shortcuts.length); | ||
Ti.API.info("Dynamic App Shortcut as JSON:" + JSON.stringify(shortcuts)); | ||
}); | ||
|
||
var btn4 = Ti.UI.createButton({ | ||
top: 10, height:45, title:"Count Static App Shortcuts" | ||
top: 10, height:45, title:"Count Static App Shortcuts" | ||
}); | ||
win.add(btn4); | ||
|
||
btn4.addEventListener("click",function(){ | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
var shortcutItems = appShortcuts.listStaticShortcuts(); | ||
Ti.API.info("Static App Shortcut as JSON:" + JSON.stringify(shortcutItems)); | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
var shortcuts = appShortcuts.listStaticShortcuts(); | ||
Ti.API.info("Static App Shortcut count:" + shortcuts.length); | ||
Ti.API.info("Static App Shortcut as JSON:" + JSON.stringify(shortcuts)); | ||
}); | ||
|
||
var btn5 = Ti.UI.createButton({ | ||
top: 10, height:45, title:"Dynamic Shortcut Exists?" | ||
top: 10, height:45, title:"Dynamic Shortcut Exists?" | ||
}); | ||
win.add(btn5); | ||
|
||
btn5.addEventListener("click",function(){ | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
var exists = appShortcuts.dynamicShortcutExists({ | ||
type:"contact_us" | ||
}); | ||
var msg = (exists) ? "Icon exists" : "Sorry isn't there"; | ||
alert(msg); | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
var exists = appShortcuts.dynamicShortcutExists("contact_us"); | ||
var msg = (exists) ? "Icon exists" : "Sorry isn't there"; | ||
alert(msg); | ||
}); | ||
|
||
var btn6 = Ti.UI.createButton({ | ||
top: 10, height:45, title:"Remove All Dynamic Shortcuts" | ||
top: 10, height:45, title:"Remove All Dynamic Shortcuts" | ||
}); | ||
win.add(btn6); | ||
|
||
btn6.addEventListener("click",function(){ | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
appShortcuts.removeAllDynamicShortcuts(); | ||
}); | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
appShortcuts.removeAllDynamicShortcuts(); | ||
}); | ||
|
||
var btn7 = Ti.UI.createButton({ | ||
top: 10, height:45, title:"Get shortcut by itemtype \"contact_us\"" | ||
}); | ||
win.add(btn7); | ||
|
||
btn7.addEventListener("click",function(){ | ||
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts(); | ||
var shortcut = appShortcuts.getDynamicShortcut("contact_us"); | ||
alert(shortcut); | ||
}); | ||
|
||
win.open(); | ||
|
||
--- | ||
name: ShortcutParams | ||
summary: Dictionary of options for <Titanium.UI.iOS.addDynamicShortcut>. | ||
description: | | ||
The parameters used when creating the dynamic shortcut. Must include the `itemtype` and `title` properties. | ||
properties: | ||
- name: type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
summary: The unique key for the application shortcut. | ||
type: String | ||
optional: false | ||
|
||
- name: title | ||
summary: The title of the application shortcut | ||
type: String | ||
optional: false | ||
|
||
- name: subtitle | ||
summary: The subtitle displayed on the application shortcut | ||
type: String | ||
optional: true | ||
|
||
- name: icon | ||
summary: | | ||
The icon to be displayed on the application shortcut, for example <Titanium.UI.iOS.SHORTCUT_ICON_TYPE_COMPOSE>. | ||
Note: You can also use a local image specified by the image path. | ||
type: Number | ||
constants: Titanium.UI.iOS.SHORTCUT_ICON_TYPE_* | ||
optional: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add that it is "read-only" - that changing the returned object will not have any effect.