diff --git a/src/index.ts b/src/index.ts index de1d6bd1eb..774886eeab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,7 @@ import { ImagePicker } from './plugins/imagepicker'; import { ImageResizer } from './plugins/imageresizer'; import { InAppBrowser } from './plugins/inappbrowser'; import { Insomnia } from './plugins/insomnia'; +import { Instagram } from './plugins/instagram'; import { Keyboard } from './plugins/keyboard'; import { LaunchNavigator } from './plugins/launchnavigator'; import { LocalNotifications } from './plugins/localnotifications'; @@ -151,6 +152,7 @@ export { GoogleAnalytics, Hotspot, Insomnia, + Instagram, Keyboard, NativeAudio, NativeStorage, @@ -225,6 +227,7 @@ window['IonicNative'] = { ImagePicker: ImagePicker, ImageResizer: ImageResizer, InAppBrowser: InAppBrowser, + Instagram: Instagram, Keyboard: Keyboard, LaunchNavigator: LaunchNavigator, LocalNotifications: LocalNotifications, diff --git a/src/plugins/instagram.ts b/src/plugins/instagram.ts new file mode 100644 index 0000000000..7ad21515c5 --- /dev/null +++ b/src/plugins/instagram.ts @@ -0,0 +1,57 @@ +import {Plugin, Cordova} from './plugin'; + +/** + * @name Instagram + * @description Share a photo with the instagram app + * + * @usage + * ``` + * import {Instagram} from 'ionic-native'; + * + * Instagram.share('data:image/png;uhduhf3hfif33', 'Caption') + * .then(() => console.log('Shared!')) + * .catch((error: any) => console.error(error)); + * + * ``` + */ +@Plugin({ + plugin: 'cordova-instagram-plugin', + pluginRef: 'Instagram', + repo: 'https://github.com/vstirbu/InstagramPlugin' +}) +export class Instagram { + + /** + * Detect if the Instagram application is installed on the device. + * + * @return {Promise} Returns a promise that returns a boolean value if installed, or the app version on android + */ + @Cordova({ + callbackStyle: 'node' + }) + static isInstalled(): Promise {return;} + + /** + * Share an image on Instagram + * Note: Instagram app stopped accepting pre-filled captions on both iOS and Android. As a work-around, the caption is copied to the clipboard. You have to inform your users to paste the caption. + * + * @param canvasIdOrDataUrl The canvas element id or the dataURL of the image to share + * @param caption The caption of the image + * @return {Promise} Returns a promise that resolves if the image was shared + */ + @Cordova({ + callbackStyle: 'node' + }) + static share(canvasIdOrDataUrl: string, caption?: string): Promise {return;} + + /** + * Share a library asset or video + * @param assetLocalIdentifier A local fileURI + * @return {Promise} Returns a promise that resolves if the image was shared + */ + @Cordova({ + callbackOrder: 'reverse' + }) + static shareAsset(assetLocalIdentifier: string): Promise {return;} + +} diff --git a/src/plugins/plugin.ts b/src/plugins/plugin.ts index 1be9f85088..3adc4eeccf 100644 --- a/src/plugins/plugin.ts +++ b/src/plugins/plugin.ts @@ -48,6 +48,14 @@ function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Func // Get those arguments in the order [resolve, reject, ...restOfArgs] args.unshift(reject); args.unshift(resolve); + } else if (opts.callbackStyle === 'node') { + args.push((err, result) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); } else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') { // If we've specified a success/error index args.splice(opts.successIndex, 0, resolve);