Skip to content

Instantly share code, notes, and snippets.

View hansemannn's full-sized avatar
🗺️

Hans Knöchel hansemannn

🗺️
View GitHub Profile
@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);
@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 / push-check.js
Last active November 12, 2018 18:28
Validate if the remote notifications dialog was accepted or not (workaround for a known Apple bug). More: https://jira.appcelerator.org/browse/TIMOB-25793
var pushRequestInitiated = false;
var deviceToken = null;
Ti.App.addEventListener('resume', function(e) {
Ti.API.warn('RESUME');
});
Ti.App.addEventListener('resumed', function(e) {
Ti.API.warn('RESUMED');
@hansemannn
hansemannn / admob-gdpr.js
Last active February 12, 2019 03:54
Native GDPR-compliant AdMob implementation using Titanium
var AdMob = require('ti.admob');
var win = Ti.UI.createWindow({
backgroundColor: 'black'
});
var items = [{
properties: {
title: 'requestConsentInfoUpdateForPublisherIdentifiers()',
itemId: 'requestConsentInfo'
@hansemannn
hansemannn / titanium-location-monitoring.js
Last active February 12, 2019 03:55
Background location monitoring in Titanium (updated for iOS 11+)
/*
⚠️ Required plist entries:
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<!-- For iOS 11+, you need "Always and When in Use" even when requesting "Always" -->
@hansemannn
hansemannn / CXCallObserver-example.js
Last active January 29, 2020 22:40
CXCallObserver in Hyperloop and Titanium
var CXCallObserver = require('CallKit/CXCallObserver'); // Require native class from CallKit
var CallDelegate = require('callDelegate'); // Require delegate class from app/lib/ (Alloy) or Resources/ (Classic)
var myDelegate = new CallDelegate(); // Instantiate Delegate
myDelegate.callChanged = function (callObserver, call) {
if (call.hasConnected) {
Ti.API.info('********** voice call connected **********\n');
} else if(call.hasEnded) {
Ti.API.info('********** voice call disconnected **********/n');
}
@hansemannn
hansemannn / titanium.js
Created March 20, 2018 10:23
To be used in Hyperloop 3.1.0 and later. Use today by replacing it in <project>/modules/iphone/hyperloop/<version>/hooks/generate/templates/builtins/titanium.js
module.exports = function (json, callback) {
// if we have no usage of hyperloop just return
if (!json) { return callback(); }
// map in our TiApp file
json.classes.TiApp = {
framework: 'Titanium',
name: 'TiApp',
methods: {
app: {
@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 / CoreLocation-iOS11.js
Last active February 28, 2018 08:42
Use the iOS 11+ CoreLocation API's to geocode addresses in Titanium and Hyperloop.
import { CLGeocoder, CLLocation } from 'CoreLocation';
import { NSLocale } from 'Foundation';
/*
* An example class of using the iOS 11.0+ CoreLocation API's to geocode locations.
* Feel free to implement more from <http://codeworkshop.net/objc-diff/sdkdiffs/ios/11.0/CoreLocation.html>.
*
* Usage:
* import TiGeocoder from 'geocoder';
* Geocoder.reverseGeocodeLocation({
@hansemannn
hansemannn / ssdp-titanium-hyperloop.js
Last active February 13, 2018 20:00
Use SSDP Services in Titanium using Hyperloop and CocoaSSDP
/*
* SSDP Services in Titanium using Hyperloop
*
* Based on https://github.com/sboisson/CocoaSSDP
* Ensure to add `CocoaSSDP` to your Podfile first!
*/
var SSDPService = require('CocoaSSDP/SSDPService');
var SSDPServiceBrowser = require('CocoaSSDP/SSDPServiceBrowser');