Last active
May 30, 2019 11:21
-
-
Save benbahrenburg/ffafdd6f5f1e88d5402a to your computer and use it in GitHub Desktop.
Titanium Spotlight Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Titanium.UI.createWindow({ | |
title:'Demo', backgroundColor:'#fff',layout:'vertical' | |
}); | |
var btnSpotLightSupported = Ti.UI.createButton({ | |
top:20, title:'Is SpotLight Supported?', | |
height:60, width:Ti.UI.FILL | |
}); | |
win.add(btnSpotLightSupported); | |
btnSpotLightSupported.addEventListener('click',function(d){ | |
var indexer = Ti.App.iOS.createSearchableIndex(); | |
if(indexer.isSupported()){ | |
alert("SpotLight is supported"); | |
}else{ | |
alert("SpotLight is not supported on your device"); | |
} | |
}); | |
var btnSpotLightTest = Ti.UI.createButton({ | |
top:20, title:'SpotLight Test', | |
height:60, width:Ti.UI.FILL | |
}); | |
win.add(btnSpotLightTest); | |
btnSpotLightTest.addEventListener('click',function(d){ | |
spotlightTest(); | |
}); | |
var btnSLActivityTest = Ti.UI.createButton({ | |
top:20, title:'Activity With SpotLight Test', | |
height:60, width:Ti.UI.FILL | |
}); | |
win.add(btnSLActivityTest); | |
btnSLActivityTest.addEventListener('click',function(d){ | |
activityPlusSplotlightTest(); | |
}); | |
var btnSLDeleteTest1 = Ti.UI.createButton({ | |
top:20, title:'Delete by identifier', | |
height:60, width:Ti.UI.FILL | |
}); | |
win.add(btnSLDeleteTest1); | |
btnSLDeleteTest1.addEventListener('click',function(d){ | |
var identifiers = ["my-id"]; | |
var indexer = Ti.App.iOS.createSearchableIndex(); | |
indexer.deleteSearchableItemsByIdentifiers(identifiers,function(e){ | |
if(e.success){ | |
alert("Everything has been deleted, press home button and search to verify"); | |
}else{ | |
alert("Errored: " + JSON.stringify(e.error)); | |
} | |
}); | |
}); | |
var btnSLDeleteTest2 = Ti.UI.createButton({ | |
top:20, title:'Delete by domainIdentifier', | |
height:60, width:Ti.UI.FILL | |
}); | |
win.add(btnSLDeleteTest2); | |
btnSLDeleteTest2.addEventListener('click',function(d){ | |
var domainIDs = ["com.mydomain"]; | |
var indexer = Ti.App.iOS.createSearchableIndex(); | |
indexer.deleteAllSearchableItemByDomainIdenifiers(domainIDs,function(e){ | |
if(e.success){ | |
alert("Everything has been deleted, press home button and search to verify"); | |
}else{ | |
alert("Errored: " + JSON.stringify(e.error)); | |
} | |
}); | |
}); | |
var btnSLDeleteTest3 = Ti.UI.createButton({ | |
top:20, title:'Delete All', | |
height:60, width:Ti.UI.FILL | |
}); | |
win.add(btnSLDeleteTest3); | |
btnSLDeleteTest3.addEventListener('click',function(d){ | |
var indexer = Ti.App.iOS.createSearchableIndex(); | |
indexer.deleteAllSearchableItems(function(e){ | |
if(e.success){ | |
alert("Everything has been deleted, press home button and search to verify"); | |
}else{ | |
alert("Errored: " + JSON.stringify(e.error)); | |
} | |
}); | |
}); | |
win.open(); | |
function spotlightTest(){ | |
var searchItem = []; | |
var itemAttr = Ti.App.iOS.createSearchableItemAttributeSet({ | |
itemContentType:"public.image", | |
title:"Titanium Core Spotlight Tutorial", | |
contentDescription:"Tech Example1 \nOn: " + String.formatDate(new Date(),"short") | |
}); | |
itemAttr.keywords = ["Mobile","Appcelerator","Titanium"]; | |
var item = Ti.App.iOS.createSearchableItem({ | |
identifier:"my-id", | |
domainIdentifier:"com.mydomain", | |
attributeSet:itemAttr | |
}); | |
searchItem.push(item); //This is an array so you can have as many as you want | |
var indexer = Ti.App.iOS.createSearchableIndex(); | |
indexer.AddToDefaultSearchableIndex(searchItem,function(e){ | |
if(e.success){ | |
alert("Press the home button and now search for your keywords"); | |
}else{ | |
alert("Errored: " + JSON.stringify(e.error)); | |
} | |
}); | |
}; | |
function activityPlusSplotlightTest(){ | |
var itemAttr = Ti.App.iOS.createSearchableItemAttributeSet({ | |
itemContentType:"public.image", | |
title:"Titanium Activity With Spotlight Tutorial", | |
genre:"Mobile Examples", | |
contentDescription:"Tech Example 2 \nOn: " + String.formatDate(new Date(),"short") | |
}); | |
itemAttr.keywords = ["Mobile","Appcelerator","Titanium"]; | |
var activity = Ti.App.iOS.createUserActivity({ | |
activityType:'com.mydomain.tutoral', title:itemAttr.title | |
}); | |
activity.addContentAttributeSet(itemAttr); | |
activity.userInfo = {name:itemAttr.title, genre: itemAttr.genre}; | |
activity.keywords = itemAttr.keywords; | |
activity.eligibleForHandoff = false; | |
activity.eligibleForSearch = true; | |
activity.becomeCurrent(); | |
alert("Press the home button and now search for your keywords"); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
itemAttr.keywords
should beitemAttr.keyWords
as written in SDK