GithubHelp home page GithubHelp logo

leecrossley / cordova-plugin-social-message Goto Github PK

View Code? Open in Web Editor NEW
121.0 19.0 44.0 32 KB

Cordova / PhoneGap Social Message Plugin for Apache Cordova >= 3.0.0

Home Page: http://ilee.co.uk

Java 38.16% Objective-C 51.53% JavaScript 10.31%

cordova-plugin-social-message's Introduction

Social Message Plugin for Apache Cordova npm version

Cordova Plugin to utilise native share features. Developed for Apache Cordova CLI >= 3.0.0. Share text, images and urls to Facebook, Twitter and more.

Install

Latest published version on npm (with Cordova CLI >= 5.0.0)

cordova plugin add cordova-plugin-social-message

Latest version from GitHub

cordova plugin add https://github.com/leecrossley/cordova-plugin-social-message.git

Usage

You do not need to reference any JavaScript, the Cordova plugin architecture will add a socialmessage object to your root automatically when you build.

Ensure you use the plugin after your deviceready event has been fired.

Share some text

Pass a message object with a "text" property as an argument to the send function:

var message = {
    text: "This is a test message"
};
window.socialmessage.send(message);

This example will allow the message to be shared with all built in activity types.

Specify activity types (iOS only)

To specify activity types to include as options for the user, add an "activityTypes" array to your message:

var message = {
    text: "This is a test message",
    activityTypes: ["PostToFacebook", "PostToTwitter"]
};
window.socialmessage.send(message);

This example will only allow the user to post the message to Facebook or Twitter.

A complete list of activity types can be found here. You should omit the "UIActivityType" prefix when adding to your array.

NB: Some activity types will only show as an option when they have accounts configured in the iOS settings on the device (e.g. Facebook and Twitter). This is different from having the apps installed.

Share a message with a subject

To add a subject to your message, use the "subject" property (used with activity types such as Mail):

var message = {
    subject: "Test Subject",
    text: "This is a test message",
    activityTypes: ["Mail"]
};
window.socialmessage.send(message);

Share a message with a url

To add a link to your message, use the "url" property:

var message = {
    text: "Link test",
    url: "http://ilee.co.uk"
};
window.socialmessage.send(message);

Share a message with an image

To add an image to your message, use the "image" property:

var message = {
    text: "Image test",
    image: "http://cordova.apache.org/images/cordova_bot.png"
};
window.socialmessage.send(message);

Platforms

iOS and Android.

Android quirk

Facebook does not permit you to share pre-filled text on Android, however images and urls will work.

License

MIT License

cordova-plugin-social-message's People

Contributors

leecrossley avatar possan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-social-message's Issues

Specify "activityTypes" for Android

Are you planning to add the ability to specify activity types on Android as well, or is this not possible?

The "Complete action using.." dialog I am getting is extremely long and contains lots of items that I'd like to remove (including Barcode, Bluetooth, Covert to PDF, QR Code, Send Tab to Devices, etc). It's especially annoying because it's longer than a single screen, and the most important ones I'd like visible, Text Message, and Twitter, are at the bottom and only visible after scrolling. Seeing options which don't make sense may confuse some users.

`

Share to single activityType

Lovely plugin. This is a feature request if you have your own interface for sharing to a specific medium.
E.g. if you in your app have "Twitter" or "Facebook" buttons to share to one or the other, it is possible (at least in the iOS SDK, don't know about Android) to fire up the share dialog instead of going through the "selection" first.
Please let me know if there's any chance that this can be implemented in your plugin.

In iOS this is accomplished with a code like:

    serviceType = SLServiceTypeFacebook;

    SLComposeViewController *viewController = [SLComposeViewController composeViewControllerForServiceType:serviceType];
    [viewController setInitialText:@"Text to share"];
    [viewController addURL:[NSURL URLWithString:@"http://example.com"]];

    viewController.completionHandler = ^(SLComposeViewControllerResult result){
        // TODO: if iOS < 7, dismiss SLComposeViewController manually because of different 

       // return some results to cordova here...

    };

    [[UIApplication sharedApplication].keyWindow.rootViewController presentModalViewController:viewController animated:YES];

plugin unsupported?

This is how I have phonegap setup:

<preference name="phonegap-version" value="3.1.0" />
<gap:plugin name="uk.co.ilee.socialmessage" />

Phonegap build gives me:

{"error":"plugin unsupported: uk.co.ilee.socialmessage"}

it's not issue but a question

I'm trying to make this plugin work with my dynamic data. So this is my code:

$http({
        method: 'POST',
        url: 'http://www.xxx.com/api/yazi.php'
    }).success(function(data, status) {
        $scope.yazi = data;
    }).error(function(data, status) {
        console.log('get movie request failed! data: ' + data);
    });

    $scope.share = function(){
        var message = {
            text: $scope.yazi.post_title,
            image: $scope.yazi.image_url,
            url: $scope.yazi.guid
        };
        $window.socialmessage.send(message);
    };

It's getting data and binding to $scope in order to use in view side.. That's normal angular implementation. But this is not working.

But If I use like this it's working:

var message = {
    text: "Image test",
    image: "http://cordova.apache.org/images/cordova_bot.png"
};

It shouldn't be a problem If I use the plugin with dynamic data, right?
Is there any suggestion?
Thanks.

Message.text is not displayed on Facebook

When shared on Facebook and simply with the message object (with text and url), the url is well loaded but the text is not displayed, even though in Twitter, everything is displayed.

Support audio file

hi,

i would like to send some audio file with this plugin but when i try.
it send audio file like picture.

like that :

var message = {
text: txtmms,
audio: "http://quoteit.fr/quote.mp3"
};

if (image != null && image.length() > 0) {
sendIntent.setType("image/*");
final URL url = new URL(image);
String storageDir = Environment.getExternalStorageDirectory().getPath();
final String path = storageDir + "/" + image.substring(image.lastIndexOf("/") + 1, image.length());
cordova.getThreadPool().execute(new Runnable() {
@OverRide
public void run() {
try {
saveImage(url, path);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
cordova.getActivity().startActivityForResult(sendIntent, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} else {
sendIntent.setType("text/plain");
cordova.startActivityForResult(this, sendIntent, 0);
}
}

public static void saveImage(URL url, String outputPath) throws IOException {
    InputStream is = url.openStream();
    OutputStream os = new FileOutputStream(outputPath);
    byte[] b = new byte[2048];
    int length;
    while ((length = is.read(b)) != -1) {
        os.write(b, 0, length);
    }
    is.close();
    os.close();
}

How can i change that code for accept audio file from url ?

thx a lot.
Sorry for my french

Crash with iPad and iOS 8

Hello!

I was testing an app with the iPad Simulator and iOS 8 and as soon as the social message code gets executed I get a crash. It only happens with the iPad and iOS 8 combination though, it seems to work fine on iPhone / iOS 8, and iPad iOS 7. Can anyone take a look at it to see what's going on?

(Cordova 3.4.0)

Thanks!

2014-10-22 15:51:42.173 FI[11166:161408] THREAD WARNING: ['SocialMessage'] took '110.743896' ms. Plugin should use a background thread.
2014-10-22 15:51:42.178 FI[11166:161408] Assuming sourceView is not nil
2014-10-22 15:51:47.186 FI[11166:161408] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7f981d54bee0>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001062c13f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001097adbb7 objc_exception_throw + 45
2 UIKit 0x0000000106dc704f -[UIPopoverPresentationController presentationTransitionWillBegin] + 2650
3 UIKit 0x00000001067b18c7 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 1398
4 UIKit 0x00000001067b0366 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 175
5 UIKit 0x00000001066d0461 _applyBlockToCFArrayCopiedToStack + 314
6 UIKit 0x00000001066d02db _afterCACommitHandler + 516
7 CoreFoundation 0x00000001061f6347 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
8 CoreFoundation 0x00000001061f62a0 __CFRunLoopDoObservers + 368
9 CoreFoundation 0x00000001061ec0d3 __CFRunLoopRun + 1123
10 CoreFoundation 0x00000001061eba06 CFRunLoopRunSpecific + 470
11 GraphicsServices 0x000000010af529f0 GSEventRunModal + 161
12 UIKit 0x00000001066ad550 UIApplicationMain + 1282
13 FI 0x0000000105f89907 main + 71
14 libdyld.dylib 0x0000000109f09145 start + 1
15 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Add email subject

Can you enhance it so that you could pass the email subject as well (to be used only if the user chooses email of course)?

Share Image and Url

Great Plugin, simple to setup and use.

BUT

I need more functionality such as sharing images and links before I can replace the other plugins that I use.

Do you know when this plugin might be a little more feature complete?

Implementation Issue

I create my project of cordova, like this:

./create ~/Desktop/myapp com.example.myapp myapp

But I can't implement your plugin, can you explain me how to implement in that case, believe me, I need to make it in that way.

Missing Facebook and Twitter icon

On iPhone 4 with iOS 7.0.4 and Phonegap 3.2, Facebook and Twitter icon are missing, i see only Email and Message share, this is my code:

var message = {
subject: "Subject",
text: "Text message",
activityTypes: ["Mail", "Message", "Facebook", "Twitter"]
};
window.socialmessage.send(message);

text not showing up in Android (for the FB post)

Lee is this my issue, something wrong or missing with what am I doing?
id="socialmessage" version="0.2.4"
cordova 3.3.0
android 4.2.2

iOS is working fine no problems. (FB twitter email)
Android shows up a blank FB window without the text inside.
No issues for the email, text is showing as expected. Did not try twitter.

var message = {
text: "Today my weight is 90kg"
};
window.socialmessage.send(message);

WBR Sasha

Can you add Android support

I love this plugin and use it successfully on iOS. Can you add Android support? This would be really helpful for a project that I'm shipping next spring.

Can't make it to work

Hi,
I did try the plugin, it's not working. I can see that my js is working.
Here is what I did
cordova create ./projet projetsname
cordova plugin add https://github.com/leecrossley/cordova-plugin-social-message.git
then added a this line to the default app : , <a href="" onClick="window.socialmessage.send("This is a test message", ["PostToFacebook", "PostToTwitter"]);">Test , and nothing is happening

Thanks

Custom text for Twitter

I want to provide different textes for the different channels. For example, the text for the mail is another one than the text for twitter, because twitter allows only 140 characters.

Is it possible to support a custom text for Twitter?

Success (and error) callbacks

Enhancement request received from my blog:

I LOVE THIS PLUGIN! Really great job! Hey, I have a request... can socialmessage.send() return some variable stating if a message was actually sent? like maybe an error code with zero being successful. I want to give my customers a bump if they actually send a message, but if they bail or cancel before sending, they get nada. thoughts?

What about google+?

Hi,
I am finding something around g+ to share text and link, so how would i be able to do this?
Please let me know the solution.

Thanks
Shivam

Cordova 3.4.1 Android - Adding social plugin overwrites all other plugins in config.xml

Specifically in Android,

When I add your social message plugin and run cordova prepare android, it overwrites all the existing plugin features in the res/xml/config directory. Removing your plugin and then preparing again will add all the the other plugins back. But anytime your plugin is added I loose the other plugin feature entries.

Basically this breaks the process in Android and I have to manaully edit the config.xml file after every prepare.

Note: This works fine in iOS. Not sure if your issue or a cordova issue. This wasn't a problem in previous releases.

Telerik AppBuilder

Have you tried Telerik AppBuilder? Does your plug in work with this?
A lot of programmers are using this as it abstracts the phonegap details and can make it easier...

Just curious
Robert

Reapet send

Hi! Good plugin! But I have problems.
i send sms - ok, but when i repeat send sms js dont work. I have error in console

Uncaught TypeError: Object PostToFacebook,PostToTwitter,PostToWeibo,Message,Mail,Print,CopyToPasteboard,AssignToContact,SaveToCameraRoll has no method 'join' at file:///android_asset/www/plugins/socialmessage/www/socialmessage.js:17
How to fix this?

My code:

<script type="text/javascript">
        var message = {
            text : "This is a test message"
        };
    </script>

    <button onclick="window.socialmessage.send(message); ">
        Share This
    </button>
</p>

This code didnt work, why?

<script type="text/javascript">
        //$(function() {
        //  $("#btn").click(function() {
        //      window.socialmessage.send($("#txt").val());
        //  });
        //});

        $(document).ready(function() {
            $("#btn").click(function() {
                window.socialmessage.send($("#txt").val());
            });
        });

        app.initialize();
    </script>
</head>
<body>
        <span id="txt">Hello world!</span>
    <p>
        <button id="btn">
            Share This
        </button>
    </p>

license?

Are we able to use this code, is it released under a license?

Thanks

Game Center share achievement or leaderboard crash iPad iOS8

Hello everyone I am trying to implement Game Center on my iOS8 app and have run into a crash on the iPad. I already have the achievements and leaderboards set up and can successfully hit the blue share button on the iPhone but when i press that on the iPad the GameCenterViewController crashes and gives me the following report:

Any help would be appreciated thank you!

Process: GameCenterUIService [485]
Path: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Applications/GameCenterUIService.app/GameCenterUIService
Identifier: GameCenterUIService
Version: 194.15 (194.15)
Code Type: X86 (Native)
Parent Process: launchd_sim [435]
Responsible: launchd_sim [435]
User ID: 501

Date/Time: 2014-12-08 07:40:13.968 -0600
OS Version: Mac OS X 10.10.1 (14B25)
Report Version: 11
Anonymous UUID: 848A566C-30DD-CDE5-1E9D-4FD32CF28CAC

Time Awake Since Boot: 770 seconds

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000

Application Specific Information:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7b1480a0>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'
terminating with uncaught exception of type NSException
abort() called
CoreSimulator 110.4 - Device: iPad Retina - Runtime: iOS 8.1 (12B411) - DeviceType: iPad Retina

TypeError: Cannot read property 'send' of undefined

I was trying to create a basic share option in my app which I'm trying on ionic framework. I'm getting this below error in console upon clicking share.

TypeError: Cannot read property 'send' of undefined

This is the code that I've used to implement share. Can you tell where I'm going wrong.

$scope.share = function($index){
        window.socialmessage.send({
            url: $scope.blogs[$index].URL
        });
    }

Instapaper support?

Hey I'm just curious, how would I be able to pass a message to an app that isn't a Built-in Activity Types like instapaper for instance?

Can't post images to facebook

If I include an image or attachment as part of the message, facebook is not offered as an option in the select list displayed on my device. Works fine with email though. Testing on an HTC One running Android 4.2.

Image: Only takes a link not an object?

Hi lesscrossley,

I am developing an application for college, thanks so much for this.

I was wondering, instead of having a link in the image property can I put an image object/src? (PS: I know you said no to file system paths, but I wasn't sure about image objects)

In my application I have just snapped a picture and I need to share it with your plugin. (ie. I have a new Image() object!).

Please let me know, if this works in your plugin it would be just perfect for my app!

If not, do you know of any other way I can do this? I am on a major time crunch here :(

Thanks, once again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.