Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working with Cordova 2.5 #3

Open
eknip opened this issue Apr 11, 2013 · 32 comments
Open

not working with Cordova 2.5 #3

eknip opened this issue Apr 11, 2013 · 32 comments

Comments

@eknip
Copy link

eknip commented Apr 11, 2013

After installing the plugin on a fresh codebase (Cordova 2.5) it doesn't seem to work as expected:

  • The window.plugins.social.available event always returns false, even when social accounts have been added in iOS.
  • When I'm firing the window.plugins.social.share event (without a check for window.plugins.social.available), sharing works via Twitter, but only tweets the text and not the attached URL.
@Jelmeaux
Copy link

The first problem is easily fixed. The available function expects a callback function, which in turn gets a variable that is either 1 or 0, not true or false.

Using a callback and checking on 1 or 0 will fix your first issue.

I've also got the second problem. I send a title, link and image, but only the title seems to be actually used.

A fix would be great!

@alexkravets
Copy link

+1 to the problem with missing URL (and IMAGE)

@alexkravets
Copy link

Guys, do you have an idea on how to fix URL sharing?

@emilycestmoi
Copy link
Owner

I'm still using Cordova 2.2 on my projects but I don't see why there would be any issues with 2.5 as the actual plugin is dead simple. Make sure the image you are passing is relative to the app's base directory and not www. So something like 'www/images/image.jpg'. I haven't had any problems with the URLs myself except when passing dead or not-live URLs--I haven't looked into this but it appears the social framework must be doing some validation on the URL before showing it--perhaps this is your problem?

@alexkravets
Copy link

Thanks for quick reply! Is image parameter required? I'm trying to make a post with message and URL only, do you know if that's an option. The URL is valid youtube video link.

Thanks for your help!

@alexkravets
Copy link

Everything works good with local images attached. Checked with cordova-2.5.

@thejwalker
Copy link

Does anyone have this working with 2.6? I followed the instructions but the plugin isn't doing anything.

Thanks

@vick08
Copy link

vick08 commented Apr 22, 2013

Hi,
I am also trying to use this plugin with Cordova 2.6.0 and am having no luck sharing anything. When checking window.plugins.social.available, I get a positive response. However, calling window.plugins.social.share with any number of parameters simply doesn't do anything.
The plugin seems to be compiling fine according to the "build" script in the "Cordova" folder of my project.

@vick08
Copy link

vick08 commented Apr 23, 2013

All working now.
Two things you need to remember to do:

  1. In config.xml specify "Social" for both name and value (yes, uppercase S, otherwise it won't work).
<plugin name="Social" value="Social" /> 1. When providing image URL, make sure to include relative path to your image including the "www" (just as the Readme says). window.plugins.social.share('This is my test message', 'http://www.url.com', 'www/images/myImage.png');

Everything should work then even under Cordova 2.6.0.

PS This is a fairly fragile plugin but it does the job. Thanks a lot for this!

@swilla
Copy link

swilla commented May 3, 2013

I was having a similar problem. The way I fixed it was adding the Social.h and Social.m files to the Xcode project. I thought adding the files to the directory was enough, you need to right click on the plugins folder in Xcode then click add files to the project. Then select the two files. Once I did that everything worked great!

@brawlins4
Copy link

Is there a way to have an image that you take with your phone's camera be the image that is shared instead of a predefined image? How would one go about doing that?

@swilla
Copy link

swilla commented May 8, 2013

You'd have to use the Capture API in phonegap. Then use the captureSuccess callback.
http://docs.phonegap.com/en/2.7.0/cordova_media_capture_capture.md.html#Capture

@brawlins4
Copy link

Sorry I should have been a little more specific. I already have the camera function set up. I was just wondering what I would have to put in place of the image location to get the image that I have taken with the camera to share. How would I tell the plugin to share the image that was just taken instead of a predefined image. Thanks for your reply swilla!

@vick08
Copy link

vick08 commented May 8, 2013

Hi,
I don't think the question is relevant to this issue.
For what you want to do, you will need to extract the path of the file from the iOS file system. It's a bit too long to describe here but searching StackOverflow will turn in a lot of good answers.

@apolinario
Copy link

What if I want to share only the title and a URL, without an attached image, isn't there a way?

@vick08
Copy link

vick08 commented May 11, 2013

I am almost sure you can simply use empty quotes and the plugin will not post any image for you.

@apolinario
Copy link

When I do that, the 'url' parameter is ignored as well, and only the title is shared

@vick08
Copy link

vick08 commented May 12, 2013

Hmmm. This will probably require a little digging then.
I will have a look in a day or two.

On May 11, 2013, at 1:35 PM, apolinario [email protected] wrote:

When I do that, the 'url' parameter is ignored as well, and only the title is shared


Reply to this email directly or view it on GitHub.

@apolinario
Copy link

Ok. I'll look forward to it. I really don't have a local image to share in every link I'd like to share

@originalp
Copy link

Stopped working completely! I've added this plugin more than 3 times already and I don't know what makes it stop working once a get it to work for a while. I had recently added the Facebook SDK and all it's required frameworks.
I've done everything on the readme::
copy the plugins to the Cordova plugins folder, copy the js to my www/js and reference it, set up the config.xml, and added the social and accounts frameworks.
PLEASE, PLEASE HELP!!
Xcode 4.6.2, iOS simulator 6.1, Phonegap 2.8.1

@vick08
Copy link

vick08 commented Jun 14, 2013

You shouldn't need Facebook SDK for this to work.
Could you try with the latest version of Phonegap? I've confirmed it working on 2.6.0 and above.
Are you getting any errors in Xcode's console?

On Jun 14, 2013, at 10:18 AM, originalp [email protected] wrote:

Stopped working completely! I've added this plugin more than 3 times already and I don't know what makes it stop working once a get it to work for a while. I had recently added the Facebook SDK and all it's required frameworks.
I've done everything on the readme::
copy the plugins to the Cordova plugins folder, copy the js to my www/js and reference it, set up the config.xml, and added the social and accounts frameworks.
PLEASE, PLEASE HELP!!
Xcode 4.6.2, iOS simulator 6.1


Reply to this email directly or view it on GitHub.

@originalp
Copy link

Facebook SDK is for another purpose.

Not getting any errors, just not working.

Sent from Mailbox for iPhone

On Fri, Jun 14, 2013 at 2:22 PM, Victor Tsaran [email protected]
wrote:

You shouldn't need Facebook SDK for this to work.
Could you try with the latest version of Phonegap? I've confirmed it working on 2.6.0 and above.
Are you getting any errors in Xcode's console?
On Jun 14, 2013, at 10:18 AM, originalp [email protected] wrote:

Stopped working completely! I've added this plugin more than 3 times already and I don't know what makes it stop working once a get it to work for a while. I had recently added the Facebook SDK and all it's required frameworks.
I've done everything on the readme::
copy the plugins to the Cordova plugins folder, copy the js to my www/js and reference it, set up the config.xml, and added the social and accounts frameworks.
PLEASE, PLEASE HELP!!
Xcode 4.6.2, iOS simulator 6.1


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub:
#3 (comment)

@vick08
Copy link

vick08 commented Jun 16, 2013

Can you share the piece of your code where you're calling Social plugin?
WIthout some repro steps it's hard to say why things may not be working. I can't imagine much could have changed since Cordova 2.5.

On Jun 14, 2013, at 12:54 PM, originalp [email protected] wrote:

Facebook SDK is for another purpose.

Not getting any errors, just not working.

Sent from Mailbox for iPhone

On Fri, Jun 14, 2013 at 2:22 PM, Victor Tsaran [email protected]
wrote:

You shouldn't need Facebook SDK for this to work.
Could you try with the latest version of Phonegap? I've confirmed it working on 2.6.0 and above.
Are you getting any errors in Xcode's console?
On Jun 14, 2013, at 10:18 AM, originalp [email protected] wrote:

Stopped working completely! I've added this plugin more than 3 times already and I don't know what makes it stop working once a get it to work for a while. I had recently added the Facebook SDK and all it's required frameworks.
I've done everything on the readme::
copy the plugins to the Cordova plugins folder, copy the js to my www/js and reference it, set up the config.xml, and added the social and accounts frameworks.
PLEASE, PLEASE HELP!!
Xcode 4.6.2, iOS simulator 6.1


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub:
#3 (comment)

Reply to this email directly or view it on GitHub.

@thomasthesecond
Copy link

Add me to the list of people who can only share the text. No URL and no image, although I am trying to load an image URL of an image hosted on Amazon S3. I know you stated you have not tested image URLs, but can anyone point me in the right direction so I can get this working? Would that be an issue with this plugin or with the Sharing framework?

@thomasthesecond
Copy link

I've sorted out my aforementioned issues with help from benwilkins (Actually, he did all of the work). Planning on forking with the updates.

@reallybigpictures
Copy link

Hmmmmm seems to have an issue not loading in Cordova 2.9

@Jelmeaux
Copy link

@thomasthesecond Could you share how you did this? Just adding a complete url doesn't work as you say, but my knowledge of Coacoa is limited at best :)

@thomasthesecond
Copy link

I'm just going to post the code that I'm using in Social.m verbatim; I figured it would be easier that way. Hope it helps. And again, thanks to benwilkins.

//
//  Social.m
//
//  Cameron Lerch
//  Sponsored by Brightflock: http://brightflock.com
//

#import "Social.h"

@interface Social ()

@end

@implementation Social

- (void)available:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
    BOOL avail = false;

    if (NSClassFromString(@"UIActivityViewController")) {
        avail = true;
    }

    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:avail];
    [self writeJavascript:[pluginResult toSuccessCallbackString:[arguments objectAtIndex:0]]];
}

- (void)share:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {

    if (!NSClassFromString(@"UIActivityViewController")) {
        return;
    }

    NSString *text = [arguments objectAtIndex:1];

    NSString *imageName = [arguments objectAtIndex:2];
    UIImage *image = nil;

    // Check if this is a cached image.
    if ([imageName rangeOfString:@"http://"].location == NSNotFound) {
        if (imageName) {
            image = [UIImage imageNamed:imageName];
        }
    // No? Then it must be an external image.
    } else {
        image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageName]]];
    }


    NSString *urlString = [arguments objectAtIndex:3];
    NSURL *url = nil;

    if (urlString) {
        url = [NSURL URLWithString:urlString];
    }

    NSArray * activityItems = @[text, [NSURL URLWithString:urlString], image];

    NSArray * applicationActivities = nil;
    NSArray * excludeActivities = @[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeMessage];

    UIActivityViewController *activityVC =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:applicationActivities];

    activityVC.excludedActivityTypes = excludeActivities;

    [self.viewController presentViewController:activityVC animated:YES completion:nil];
}

@end

@Jelmeaux
Copy link

I've tried it with your code. Local images still work, although some options are now no longer available in the share screen (Facebook, Print etc).

When trying to share an external image, the app breaks with the following error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]'

Any ideas?

@thomasthesecond
Copy link

I'm sorry, I can't really help you beyond the code I posted. I don't know Obj-C at all.

As far as the share options go, you can add/remove what you want excluded by editing this line:

NSArray * excludeActivities = @[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeMessage];

@vick08
Copy link

vick08 commented Aug 2, 2013

Wouldn't posting external images break cross-domain security rules? I am not sure if such posting is possible using standard iOS flows. I believe you have to cash the image first and then post its local copy through to the framework.

On Jul 23, 2013, at 7:58 AM, Jelmer van Dulst [email protected] wrote:

I've tried it with your code. Local images still work, although some options are now no longer available in the share screen (Facebook, Print etc).

When trying to share an external image, the app breaks with the following error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]'

Any ideas?


Reply to this email directly or view it on GitHub.

@Gapz
Copy link

Gapz commented Sep 6, 2013

I can see Twitter but Facebook has disappeared, any idea why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests