Skip to content

Instantly share code, notes, and snippets.

View hansemannn's full-sized avatar
🗺️

Hans Knöchel hansemannn

🗺️
View GitHub Profile
@hansemannn
hansemannn / ti.speech.example.js
Created April 8, 2019 05:29
Realtime Speech Recognition in Titanium
var TiSpeech = require('ti.speech');
TiSpeech.initialize('en_US'); // locale is optional
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var currentValue = '';
@hansemannn
hansemannn / deep-linking-manager.js
Created May 20, 2019 10:06
Titanium Deep Linking Manager (iOS)
export default class DeepLinkingManager {
constructor () {
this.handledLinks = {};
this.activityType = 'io.lambus.app.universalLink';
const activity = Ti.App.iOS.createUserActivity({
activityType: this.activityType
});
@hansemannn
hansemannn / push-manager.js
Created October 15, 2019 15:28
Handle iOS push notifications in Appcelerator Titanium
import FirebaseMessaging from 'firebase.cloudmessaging';
export default class PushManager {
listenForPushNotifications() {
// Called when the Firebase token is ready
FirebaseMessaging.addEventListener('didRefreshRegistrationToken', event => {
const fcmToken = event.fcmToken;
// Update push token here …
@hansemannn
hansemannn / app-utils.js
Last active October 15, 2019 20:16
Using ES7+ async/await in Appcelerator Titanium
export function showOptions (args) {
const title = args.title;
const message = args.message;
const options = args.options;
const destructive = args.destructive !== undefined ? args.destructive : -1;
let cancel = -1;
return new Promise((resolve, reject) => {
if (OS_IOS) {
options.push('Cancel');
@hansemannn
hansemannn / cache.js
Created December 12, 2018 10:19
Caching remote images in Titanium (asynchronously)
export default class Utils {
static loadCachedImageFromURL(url, cb) {
let filename;
try {
filename = url.substring(url.lastIndexOf('/') + 1);
} catch (err) {
cb(null);
}
@hansemannn
hansemannn / app.js
Created July 11, 2018 02:00
Microphone monitoring in Appcelerator Titanium using the AVAudioRecorder API
'use strict';
var ButtonTitle = {
START: 'Start Microphone Monitoring',
STOP: 'Stop Microphone Monitoring'
};
Object.freeze(ButtonTitle);
var started = false;
@hansemannn
hansemannn / av-merge.js
Last active June 9, 2019 16:37
Merge Audio- and Video-tracks in iOS using Titanium and Hyperloop
import {
AVMutableComposition,
AVURLAsset,
AVAsset,
AVMutableCompositionTrack,
AVAssetExportSession,
AVFoundation
} from 'AVFoundation';
import { NSArray, NSURL, Foundation } from 'Foundation';
@hansemannn
hansemannn / loader.js
Created May 28, 2019 11:41
A cross platform modal loading indicator to use in Appcelerator Titanium
import TiAnimation from 'ti.animation';
/**
* A loader class to show a modal loading indicator
* above the current context (even above modal).
*
* Author: Hans Knöchel
*
*/
export default class Loader {
func handleData() {
let jsonData: [String: Any]
let text = String(describing: self.data)
// JSON serialisation can fail, use do-catch (like try-catch in
// to cope with possible failuresJava/C)
do {
// JSON data is copied into a key/value dictionary
jsonData = try JSONSerialization.jsonObject(with: self.data, options: [.mutableContainers]) as! [String: Any]
} catch {
return debugPrint("Error occurred: \(error.localizedDescription)")
@hansemannn
hansemannn / TitaniumiOS12UserNotifications.js
Last active February 12, 2019 04:06
Use the iOS 12 UserNotifications API's (threadIdentifier, summaryArgument, summaryArgumentCount) in Titanium!
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var btn = Ti.UI.createButton({
title: 'Schedule Notification'
});
btn.addEventListener('click', function() {
schedule('id_1', 'New Notification', 'Hey there!', new Date().getTime() + 3000);