Take multiple pictures using Titanium/Appcelerator on iPhone - iphone

I am working on a small iPhone app using Titanium/Appcelerator. Now what I am trying to do is the following:
Open the camera to take a picture
Ask the user if he wants to add another picture (OptionDialog)
Open the camera again
{loop here}
Put the images (saved locally) into an array
I tried putting a OptionDialog into the success event of the camera, but it didn't work as expected.

maybe something like that.
dialog.addEventListener('click',function(e){
switch (e.index){
case 1:
takeAPicture();
case default:
...
};
});
function takeAPicture(){
Titanium.Media.showCamera({
success: function(evtSuccess) {
dialog.show();
},
...
});
};
Titanium.Media.takePicture();

what happened putting it into the success event? what exactly did you put into? i would put the
dialog.show();
into the success event too

Related

Why does the YouTube IFrame API for iOS devices send messages with a youtubeplayer:// protocol?

I am trying to use pieces of the YouTubePlayerKit for a project I am working on. It looks like the library does the following:
Creates a player instance from a videoId
Creates a webview to load the video in
Evaluates some JS to get the video loaded
Re: the 3rd step, I was browsing the source code and i saw this function:
// Send YouTubePlayer Event with optional data
function sendYouTubePlayerEvent(event, data) {
var locationHref = 'youtubeplayer://' + event;
if (data) {
locationHref = locationHref + '?data=' + data;
}
window.location.href = locationHref
}
What I can't understand is, why are they using a youtubeplayer:// protocol? Is it inferring where to send events based on the name of the player class? Just for reference, I was looking at this library as well, and they use the protocol ytplayer://. What's going on here?
ytplayer:// is the start of a URL
https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app
https://developer.apple.com/ios/universal-links/
From the looks of your code it would ultimately look like
youtubeplayer://play?data=fghdfgjhdfgjdfgj
With fghdfgjhdfgjdfgj being some data object.
window.location would take that URL and do something with it like set the location of the current view or direct the webview to that website.
If you look at the code for the "Widget Code Along" You will find a good example for this setup, they only glance over it in the video but a
Link in a Widget uses a URL to open the detail view of a character.
https://developer.apple.com/news/?id=yv6so7ie

How to open the bottom sheet that contains the list of applications for opening URL or google map. So the user can select their preferred application?

I tried this one. But, it Directly opens on the Google Maps application. The bottom sheet for choosing the preferred application is not showing. How do I achieve it? So, the user can select their preferred application.
This is my code for now,
try {
launchUrl(
Uri.parse("geo:${taskAddress.lat},${taskAddress.lng}"),
mode: LaunchMode.externalApplication,
);
} catch (e) {
} finally {
launchUrl(Uri.parse(
"google.navigation:q=${taskAddress.lat},${taskAddress.lng}&mode=d"));
}
I think you can't do that. It's user device preferred setting. If the user set it to "Always Open" or similar it will not ask again.

Using uni_links when the app is in the background

My application has the following structure:
- InheritedWidget for dependencies
--> Splash Screen Page
--> Login Pages
--> Main Pages
When the app runs for the first time, I can use var link = await getInitialLink(); to get the value for the link that opened the app.
However, I cannot get the same result if I open the app on the background.
I tried to use
getLinksStream().listen((link) => (link) {
try {
var _latestUri;
if (link != null) _latestUri = Uri.parse(link);
print("=== Formated successfully a link!");
} on FormatException {
print("--- A link got here but was invalid");
}
});
For getting the link in the Splash Screen, but if the app is already open in the Login or Main pages, it won't go through the Splash Screen again.
Then, I tried to put it in the InheritedWidget, but alas, didn't get any result whatsoever.
So my question is: Where and how should I set up uni_links so that I can catch all incoming links even if the app is open?
Or better, is there an alternative for App Links/Universal Links that I can use?
Though it's not the best and most elegant way, I got around this.
First, I was not using getLinksStream correctly
Instead of
(link) => (link) {...}
It's
(link) {...}
Then, I need to put this subscription in my Splash Screen and do not dispose of it, so that it can listen to new events.
If anybody has a better solution, please free to add it
For this situation, you need to use both of getInitialUri() and getUriLinksStream(),
If app launchs directly u will get uri from getInitialUri, if app already running on background u will get uri from getUriLinksStream.

Titanium: Youtube video

How can I show a youtube or bits on the run video full screen on my app? Is there a special link I have to naviate to? Or is there a special API that takes care of that to view it fullscreen?
The idea is to click on a link 'show video', then show the video fullscreen, and get a button play pauze and 'done'. When clicked done it goes back to the previous page.
I don't know how to get started on this one. Can anyone help me out?
I'm creating an iPhone app.
Thanks!
#Muhammad has the first part right but to get it to close when you hit the blue done button you'll need the following code.
replace
win.add(activeMovie);
activeMovie.play();
with
win.add(activeMovie);
activeMovie.fullscreen = 1; // this must be defined after you add to the window!
activeMovie.play();
then add this
activeMovie.addEventListener('fullscreen', function(e) {
if(!e.entering) { // this is run only when exiting fullscreen aka the blue done button
activeMovie.stop();
}
});
Here is a an example code to show video with controlls
var win = Titanium.UI.currentWindow;
var contentURL = 'http://movies.apple.com/media/us/ipad/2010/tours/apple-ipad-video-us-20100127_r848-9cie.mov';
var activeMovie = Titanium.Media.createVideoPlayer({
contentURL: contentURL,
backgroundColor:'#111',
movieControlMode:Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode:Titanium.Media.VIDEO_SCALING_MODE_FILL
});
win.add(activeMovie);
activeMovie.play();
Hope this will help.

How to Bind Load event for Image in jQueryMobile

I have a mobile website running jQuery Mobile 1.0a2 and I'm currently testing in Mobile Safari for Firmware 4.1 via the iPhone Simulator.
I cannot seem to bind to the load event for an image.
I have a simple gallery of thumbnails and a large image. When you click on a thumbnail it changes the src attribute of the main img
The js for that uses the live('click' method to bind and it works just fine.
$('.gallery-navigation img').live('click',function() {
// change source of main image to new
$.mobile.pageLoading(); // show jquerymobile loading message
});
My problem is that I need feedback on this click, so I wanted to show a loading message (provided by jquerymobile) and then hide it once the image loads.
Where #gallery_image_large is the actual <img> where the src is changing, I tried the following:
$("#gallery_image_large").bind("load", function () {
$.mobile.pageLoading(true); // hide jquerymobile loading message
});
This works in Safari on my desktop but does not in the iPhone Simulator mentioned above.
For reference:
jQuery Mobile Loading Message Methods
UPDATE: I am experimenting with JQuery Image load fails on MobiOne iPhone simulator, which explains how to implement the .load manually by "checking .complete".
I changed the structure of my jquery and it's seemed to have fixed it!
$('#gallery_image_large').one('load',function() {
try { // a grade
$.mobile.pageLoading(true);
} catch(err) { // low grade
}
}).attr('src',full_src);
(as you can see, I opt'd for a try { .. } catch { .. } to verify jquerymobile is available.
Although I didn't use the solution (directly) from JQuery Image load fails on MobiOne iPhone simulator, the manual firing of load via .complete is probably a good solution for anyone else out there!