Titanium_iphone contacts - iphone

I am trying to list contacts with Titanium. WOrks on android device, but on iphone simulator doesn't return anything.
var contacts= Ti.Contacts.getAllPeople();
alert("contacts.length");
returns 0. I am not sure what am i missing here.

Make sure that you have contacts created on your iOS simulator:
Use Home button (CMD+Shift+H) to go to dashboard.
Open up Contacts app
Create few contacts which you want to retrieve in your app.
Also before you call Ti.Contacts.getAllPeople() you have to request authorisation to contact list. Try code below:
function processContacts() {
Ti.API.info('authorized');
var contacts = Ti.Contacts.getAllPeople();
Ti.API.info(contacts.length);
}
if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED){
processContacts();
} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN){
Ti.Contacts.requestAuthorization(function(e){
if (e.success) {
processContacts();
} else {
Ti.API.info('disallowed');
}
});
} else {
Ti.API.info('disallowed');
}
One last thing, in your code you wrote: alert("contacts.length") which will always display dialog view with "contacts.length" as a string, not value. To call it properly you should write: alert(contacts.length) without double quotes.

Related

How do i make flutter application that open another app within it and not webview

I have tried to make flutter app in which within it I have a list of another application. I want on tap of any app within a list to open that app, like the code below. How to do it in flutter ?
openExternalApp : function(packageName) {
try {
var KonyMain = java.import("com.konylabs.android.KonyMain");
var context = KonyMain.getAppContext();
var pm = KonyMain.getAppContext().getPackageManager();
var intent = pm.getLaunchIntentForPackage(packageName);
if(intent !== null && intent!== undefined){
context.startActivity(intent);
}
else {
var url = "https://play.google.com/store/apps/details?id="+packageName;
kony.application.openURL(url);
}
} catch(e) {
kony.print("error opening app external: "+e)
}
}
If i understood correctly you want to do something like kindle which allows the user to open a book (in this case an app) directly from your app.
That being the case, maybe this package can help you https://pub.dev/packages/device_apps
to check for installed apps List<Application> apps = await DeviceApps.getInstalledApplications();
and to launch the app DeviceApps.openApp('package.name');
This package currently only supports android.

How to wait for PlayerPrefs.SetString to be saved on disk?

In my recent published mobile game I have implemented an online leaderboard. Some users ran into issues on registration process. In short words the registration is coded like this:
// coroutine
DownloadLeaderBoard () {
if (string.IsNullOrEmpty (PlayerPrefs.GetString ("USERNAME"))) {
RegisterUser();
yield break;
}
// Download and display Leaderboard
}
// coroutine
RegisterUser () {
// user has entered a valid username
PlayerPrefs.SetString("USERNAME" username);
DownloadLeaderboard();
}
So after I saved the username, I have to make sure that it's on the disk before I call DownloadLeaderboard() again! How can I achieve that and prevent that RegisterUser() is called multiple times?
if (PlayerPrefs.HasKey("USERNAME")) {
// dont't register user again
}

How to add popup in google vr view on the click of hotspot.

What I'm trying to do is, When I click on hotspot it should open a popup with little text. It is okay if the text is static, Is there any way we can make it possible? FYI I'm creating it for the web.
Thanks in advance:)
I just started with google VR. I know it's a late reply but it is very possible.
function onVrViewLoad() {
// init scene here and then:
vrView.on('click', onHotspotClick)
}
function onHotspotClick(e) {
console.log('onHotspotClick', e.id)
triggerSidebar(e.id)
}
function triggerSidebar(id) {
// add the class
switch (id) {
case 'item':
document.querySelector('aside.item').classList.add('...')
break
}
}

Chartboost with Swift - Interstitial: prefetch if NOT complete. wait... but no ad?

I am trying to integrate Chartboost ads in Swift into my project and have followed the tutorial verbatim:
https://answers.chartboost.com/hc/en-us/articles/205853276
Everything is imported and in App delegate I have:
Chartboost.startWithAppId(//stuff)
Chartboost.setShouldRequestInterstitialsInFirstSession(false)
Chartboost.cacheMoreApps(CBLocationHomeScreen)
//Chartboost
class func showChartboostAds()
{
Chartboost.showInterstitial(CBLocationHomeScreen);
}
func didFailToLoadInterstitial(location :String!, withError error: CBLoadError)
{
}
func didDismissInterstitial(location :String! )
{
if(location == CBLocationHomeScreen)
{
Chartboost.cacheInterstitial(CBLocationMainMenu)
}
else if(location == CBLocationMainMenu)
{
Chartboost.cacheInterstitial(CBLocationGameOver)
}
else if(location == CBLocationGameOver)
{
Chartboost.cacheInterstitial(CBLocationLevelComplete)
}
else if(location == CBLocationLevelComplete)
{
Chartboost.cacheInterstitial(CBLocationHomeScreen)
}
}
Then in my main view controlleR:
AppDelegate.showChartboostAds()
I have my app in test mode in the dashboard and am running on a real device but I just get Interstitial: prefetch if NOT complete. wait... in the console.
Why won't it show any ads?
Just an aside, the reason this solution works is because of the prefetch method. It seems when you call the ad the Chartboost prefetch isn't completing on time, which is causing the show call to fail.
Chartboost does have a delegate method that will give you the all-clear when prefetch completes, that may be worth a look: - (void)didPrefetchVideos;
Here's a link to the rest of the page.
Hope this helps.
I think you're trying to show the AD to quickly. Try delaying the AD, that solved it for me.

Preloader in Wicket Application

In a wicket application on search event it takes few secons and sometimes minutes to show the result as its a long data . I want to show a preloader while the data is fetched from the database to let the user know something is going on when they click search . I am very new to wicket application , dont understands the things very deeply but I find AjaxLazyPreloader but as I said I want to show the preloader when the search method is called ...I am sharing the SearchSubmit method ...
private void processSearchSubmit(AjaxRequestTarget ajaxRequestTarget) {
ajaxRequestTarget.add(tableHolder);
ajaxRequestTarget.add(productTableHolder);
if (zipcode == null) {
ajaxRequestTarget
.appendJavaScript("$().toastmessage('showWarningToast','Please enter a zipcode')");
} else if (!ZipCodeValidator.isValid(zipcode)) {
useZones = true;
currentZone = zipcode;
ajaxRequestTarget.add(tableHolder);
if (searchProduct != null) {
ajaxRequestTarget.add(productTableHolder);
if (lstProduct.getList().size() == 0) {
ajaxRequestTarget
.appendJavaScript("$().toastmessage('showErrorToast','Sorry! This product is not avialable .')");
}
}
} else if (lstMerchants.getList().size() == 0) {
ajaxRequestTarget
.appendJavaScript("$().toastmessage('showWarningToast','Sorry! There are currently no services')");
}
if (ZipCodeValidator.isValid(zipcode)) {
ajaxRequestTarget.add(tableHolder);
if (searchProduct != null && !searchProduct.equals("")) {
ajaxRequestTarget.add(productTableHolder);
if (lstProduct.getList().size() == 0) {
ajaxRequestTarget
.appendJavaScript("$().toastmessage('showErrorToast','Sorry! This product is not avialable in this zip code or zone.')");
}
}
}
}
I want when this method is called till the times it fetch the result data , it should show a preloader or spinner . Can anybody suggest how to do that .??
If you need to call long execution method by clicking button check this answer.
You can also use AjaxLazyLoadPanel, check this demo (it's Java part and html part)
Either use an AjaxLazyLoadPanel or an IndicatingAjaxLink/-Button. Both will work fine in either normal or Ajax calls.
To use an AjaxLazyLoadPanel: create a subclass of AjaxLazyLoadPanel which loads the panel you want to display and add it to the AjaxRequest.
IndicatingAjaxLinks just display a spinner while the request is being processed and can be used straightforward in your current application. Use this instead of the button/link you use for formsubmits now.