Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.

Commit cd3fb58

Browse files
Ethan SutinEthan Sutin
authored andcommitted
fix attribution links and add canopen cordova plugin to detect if google maps app is installed before launching directions
1 parent 2e58b02 commit cd3fb58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+9213
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"source":{"type":"git","url":"https://github.com/philbot5000/CanOpen.git","subdir":"."}}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
CanOpen
2+
======
3+
This plugin is useful for checking if native apps are installed on a user's iOS or Android device. By passing an app scheme (e.g., 'fb://', 'gplus://', 'instagram://', etc...), CanOpen returns true if it detects the user has the corresponding native app installed. By returning false, CanOpen allows the developer the ability to implement a fallback URL–for instance, the app's location in the App Store, or a mobile web version of the corresponding app. A blog post for this plugin can be found at <a href="http://philmerrell.com/canopen-a-phonegap-plugin-to-check-if-native-apps-are-installed-on-a-users-ios-device/" target="_BLANK">http://philmerrell.com/canopen-a-phonegap-plugin-to-check-if-native-apps-are-installed-on-a-users-ios-device/</a>
4+
5+
## Manual Installation for iOS
6+
7+
Copy the following files to your project's Plugins folder:
8+
9+
**CanOpen.h**<br />
10+
**CanOpen.m**
11+
12+
13+
Add a reference for this plugin to **config.xml** in your iOS phonegap project:
14+
15+
```
16+
<feature name="CanOpen">
17+
<param name="ios-package" value="CanOpen" />
18+
</feature>
19+
```
20+
21+
Add the **canOpen.js** script to your www folder and reference it in your main index.html file.
22+
23+
<script type="text/javascript" charset="utf-8" src="canOpen.js"></script>
24+
25+
## Automatic Installation
26+
27+
Working on registering CanOpen with plugman. Coming soon.
28+
29+
Usage:
30+
-------
31+
32+
**Alert a user that app is not installed.**
33+
34+
```javascript
35+
CanOpen('fb://', function(isInstalled) {
36+
37+
if(isInstalled) {
38+
39+
document.location = 'fb://';
40+
41+
} else {
42+
43+
alert('Facebook is not installed');
44+
45+
}
46+
});
47+
```
48+
49+
**Or fallback to mobile web.**
50+
51+
```javascript
52+
CanOpen('fb://', function(isInstalled) {
53+
54+
if(isInstalled) {
55+
56+
document.location = 'fb://';
57+
58+
} else {
59+
60+
document.location = 'http://m.facebook.com';
61+
62+
}
63+
});
64+
```
65+
66+
**Or fallback to app in the App Store.**
67+
68+
```javascript
69+
CanOpen('fb://', function(isInstalled) {
70+
71+
if(isInstalled) {
72+
73+
document.location = 'fb://';
74+
75+
} else {
76+
77+
document.location = 'https://itunes.apple.com/us/app/facebook/id284882215';
78+
79+
}
80+
});
81+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="com.philmerrell.cordova.canopen" version="0.1">
3+
<name>CanOpen</name>
4+
<author>Phil Merrell, Bryan Wokich</author>
5+
<description>CanOpen is useful for checking if native apps are installed on a user's device in iOS or Android.
6+
</description>
7+
<license>Apache 2.0</license>
8+
<keywords>cordova, phonegap, canopen, canopenurl, url, scheme</keywords>
9+
<engines>
10+
<engine name="cordova" version=">=3.0.0"/>
11+
</engines>
12+
<js-module src="www/canOpen.js" name="canopen">
13+
<clobbers target="window.CanOpen"/>
14+
</js-module>
15+
<platform name="ios">
16+
<config-file target="config.xml" parent="/*">
17+
<feature name="CanOpen">
18+
<param name="ios-package" value="CanOpen"/>
19+
</feature>
20+
</config-file>
21+
<header-file src="src/ios/CanOpen.h"/>
22+
<source-file src="src/ios/CanOpen.m"/>
23+
</platform>
24+
<!-- android -->
25+
<platform name="android">
26+
<config-file target="res/xml/config.xml" parent="/*">
27+
<feature name="CanOpen">
28+
<param name="android-package" value="com.soundsoftware.canopen.CanOpen"/>
29+
</feature>
30+
</config-file>
31+
32+
<source-file src="src/android/CanOpen.java" target-dir="src/com/soundsoftware/canopen"/>
33+
</platform>
34+
</plugin>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.soundsoftware.canopen;
2+
3+
import java.util.List;
4+
5+
import org.apache.cordova.CallbackContext;
6+
import org.apache.cordova.CordovaPlugin;
7+
import org.apache.cordova.PluginResult;
8+
import org.apache.cordova.PluginResult.Status;
9+
import org.json.JSONArray;
10+
import org.json.JSONException;
11+
12+
import android.content.Intent;
13+
import android.content.pm.PackageManager;
14+
import android.content.pm.ResolveInfo;
15+
import android.net.Uri;
16+
17+
public class CanOpen extends CordovaPlugin {
18+
19+
@Override
20+
public boolean execute(String action, JSONArray args,
21+
final CallbackContext callbackContext) throws JSONException {
22+
23+
PluginResult pr;
24+
Uri uriToTest = Uri.parse(args.getString(0) + "://");
25+
Intent intent = new Intent(Intent.ACTION_DEFAULT, uriToTest);
26+
PackageManager packageManager = cordova.getActivity().getPackageManager();
27+
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
28+
boolean isIntentSafe = activities.size() > 0;
29+
pr = new PluginResult(Status.OK, isIntentSafe);
30+
callbackContext.sendPluginResult(pr);
31+
return false;
32+
}
33+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// CanOpen.h
3+
// CanOpen
4+
//
5+
// Created by Phil Merrell on 10/25/13.
6+
//
7+
//
8+
9+
#import <Cordova/CDV.h>
10+
11+
@interface CanOpen : CDVPlugin
12+
13+
- (void)appCanOpen:(CDVInvokedUrlCommand*)command;
14+
15+
@end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// CanOpen.m
3+
// CanOpen
4+
//
5+
// Created by Phil Merrell on 10/25/13.
6+
//
7+
//
8+
9+
#import "CanOpen.h"
10+
#import <Cordova/CDV.h>
11+
12+
@implementation CanOpen
13+
14+
-(void) appCanOpen:(CDVInvokedUrlCommand*)command {
15+
CDVPluginResult* pluginResult = nil;
16+
NSString* appUrl = [command.arguments objectAtIndex:0];
17+
18+
if (appUrl != nil && [appUrl length] > 0) {
19+
20+
NSURL *url = [NSURL URLWithString: appUrl];
21+
BOOL result = [[UIApplication sharedApplication] canOpenURL: url];
22+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:result];
23+
24+
} else {
25+
26+
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
27+
28+
}
29+
30+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
31+
}
32+
33+
@end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = function CanOpen(app, callback) {
2+
cordova.exec(
3+
// Success callback
4+
callback,
5+
// Failure callback
6+
function(err) { console.log('Missing app scheme.');},
7+
// Native Class Name
8+
"CanOpen",
9+
// Name of method in native class.
10+
"appCanOpen",
11+
// array of args to pass to method.
12+
[app]
13+
);
14+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"source":{"type":"registry","id":"org.apache.cordova.inappbrowser"}}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!--
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
-->
21+
22+
# Contributing to Apache Cordova
23+
24+
Anyone can contribute to Cordova. And we need your contributions.
25+
26+
There are multiple ways to contribute: report bugs, improve the docs, and
27+
contribute code.
28+
29+
For instructions on this, start with the
30+
[contribution overview](http://cordova.apache.org/#contribute).
31+
32+
The details are explained there, but the important items are:
33+
- Sign and submit an Apache ICLA (Contributor License Agreement).
34+
- Have a Jira issue open that corresponds to your contribution.
35+
- Run the tests so your patch doesn't break existing functionality.
36+
37+
We look forward to your contributions!

0 commit comments

Comments
 (0)