Skip to content

Instantly share code, notes, and snippets.

View EddyVerbruggen's full-sized avatar
🔌
plugged in

Eddy Verbruggen EddyVerbruggen

🔌
plugged in
View GitHub Profile
@EddyVerbruggen
EddyVerbruggen / connectionchecker.js
Created April 11, 2014 20:33
Check for a WiFi connection in a PhoneGap app and show a message if it's not available - and stop checking
"use strict";
(function() {
var intervalID = null;
function startCheckingNetworkConnection() {
intervalID = setInterval(function() {
var networkState = navigator.connection.type;
var isWifi = networkState == Connection.WIFI;
@EddyVerbruggen
EddyVerbruggen / iOS8 Beta Phonegap fix
Last active December 8, 2018 05:28
iOS8 Beta Phonegap fix: manually set the navigator.userAgent
// temp fix for iOS8 beta 1 (fixed in beta 2), add it after the reference to cordova.js
if (navigator.userAgent === undefined) {
navigator.__defineGetter__('userAgent', function() {
return("Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit");
});
}
Run this in your Mac Terminal (assuming you have the Ionic CLI):
----------------------------------------------------------------
ionic start wkwebviewpolyfilltest
cd wkwebviewpolyfilltest
ionic setup sass
ionic platform add ios
ionic plugin add https://github.com/EddyVerbruggen/cordova-plugin-wkwebview
ionic build
----------------------------------------------------------------
@EddyVerbruggen
EddyVerbruggen / cordova-ios-3.7.0-handleopenurl-fix
Last active August 29, 2015 14:10
Cordova iOS 3.7.0 handleOpenURL coldstart fix
// I'm not saying this is the best solution, it's just a temp fix which works in my case to solve
// the issue where a passed in url is not propagated to the handleOpenURL js function upon
// coldstart on iOS Cordova 3.7.0.
// Stay tuned on this issue for a better fix: https://issues.apache.org/jira/browse/CB-7606
// replace processOpenUrl in CDVViewController.m by this:
- (void)processOpenUrl:(NSURL*)url pageLoaded:(BOOL)pageLoaded
{
NSString* readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
@EddyVerbruggen
EddyVerbruggen / MyActivityWithStatusBarColor.java
Last active August 29, 2015 14:16
Android 5.0 Lollipop statusbar color
// Inside your Activity class onCreate method add and invoke this method.
// Note that you can plug this into any Android project, you don't need to build with SDK 21 to be able to compile
private void setStatusBarColor() {
if (Build.VERSION.SDK_INT >= 21) {
final Window window = getWindow();
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
try {
@EddyVerbruggen
EddyVerbruggen / Tweet-a-selfie
Created April 13, 2015 06:01
Tweet a selfie with the Cordova SocialSharing plugin
navigator.camera.getPicture(
function(base64EncodedImg) {
// wrap in a timeout so the native view of SocialSharing doesn't collide with the one from the camera plugin
setTimeout(function() {
window.plugins.socialsharing.shareViaTwitter('Check my latest selfie. I\'m awesome!', 'data:image/jpg;base64,'+base64EncodedImg, null, null, null);
}, 500);
},
function(msg) {
alert("Error: " + msg);
},
@EddyVerbruggen
EddyVerbruggen / yourapp.plist
Last active September 11, 2015 19:03
Whitelist your server for iOS9 non-HTTPS communication
<!--
When building with XCode 7 (iOS9 SDK), Apple restricts communication to SSL servers only.
See https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/
You can override this if you need to.
If you know which servers your app talks to, look for 'NSExceptionDomains' on the page above.
But if you need to whitelist everything (not recommended) add this to your app's .plist:
-->
@EddyVerbruggen
EddyVerbruggen / app.js
Last active June 20, 2016 06:20
NativeScript 3D Touch shortcut icons
// Open your app's main js file and add this handler (delimited by 'START 3DTouch wiring' and 'END 3DTouch wiring').
// Then tweak the handling of 'shortcutItem.type' to your liking (here I'm deeplinking 'compose' to the 'compose' page and ignore other shortcut types).
var application = require("application");
application.cssFile = "./app.css";
application.mainModule = "main-page";
// START 3DTouch wiring
var MyDelegate = (function (_super) {
// In case you embed a webview in a native app and the native app has a navigation bar you may find
// swiping up from the webview to the header (and releasing your finger on the header) will not fire
// a 'touchend' event on the webview.
//
// This code fixes it in a way where we listen for 'touchmove' events and fire a 'touchend' event
// programmatically in case the user leaves the webview at the top (negative Y coordinate):
document.addEventListener("touchmove", function(e) {
if (e.changedTouches[0].pageY < 0) {
e.preventDefault();
@EddyVerbruggen
EddyVerbruggen / homekit-creating-homes.ts
Last active January 12, 2017 18:08
NativeScript HomeKit - creating Homes
import { HomeKit } from "nativescript-homekit";
import { prompt, PromptResult } from "ui/dialogs";
// instantiate the plugin's main Class
const homeKit = new HomeKit();
// ask the user for a name and add it to HomeKit
prompt("Name the home").then((promptResult: PromptResult) => {
if (promptResult.result) {
homekit.addHome(promptResult.text).then(