UIActivity Controller linkedIn Post is not working - ios

LinkedIn Sharing is not working in UIActivity view controller(Without SDK), while trying to share the post. LinkedIn post is getting crashed and I am getting a crashlog like linkedIn : plugin com.linkedin.LinkedIn.ShareExtension invalidated
NSArray *items = #[shareContentHeadingString,shareUrl];
activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:items applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToWeibo];
activityViewController.excludedActivityTypes = excludeActivities;
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0")){
activityViewController.popoverPresentationController.sourceView = self.view;
}
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0")) {
sharePopOverController = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
shareRect = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 1, 1);
sharePopOverController.delegate = self;
[sharePopOverController presentPopoverFromRect:shareRect inView:self.view permittedArrowDirections:0 animated:YES];
}
else{
[self presentViewController:activityViewController animated:YES completion:nil];
}
}
else{
[self presentViewController:activityViewController animated:YES completion:nil];
}

I faced same problem. then i removed URL and Image and passed only string value to LinkedIn. and it worked.

Related

UIActivityViewController show showing ios objective c

I'm trying to present an activity view controller. but I don't know why is this error occurs again and again. Same code I have used for my other app and its working fine over there. However, in my current app its starts crashing.
NSString *url=#"http://itunes.apple.com/us/app/APPNAME/idXXXXXXXXX";
NSString * title =[NSString stringWithFormat:#"Download App %# and get free reward points!",url];
NSArray* dataToShare = #[title];
UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypeAirDrop];
if (activityViewController == nil){
return;
}
[self presentViewController:activityViewController animated:YES completion:^{}];
Try this code with main thread mention in below.
NSString *url=#"http://itunes.apple.com/us/app/APPNAME/idXXXXXXXXX";
NSString * title =[NSString stringWithFormat:#"Download App %# and get free reward points!",url];
NSArray* dataToShare = #[title];
UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypeAirDrop];
if (activityViewController == nil){
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:activityViewController animated:YES completion:^{}];
});

Sending user location to whatsapp and facebook

I am trying to send user location to facebook and whatsapp from my app by UIActivityViewController.
- (IBAction)shareUserLocation:(id)sender {
shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.apple.com/maps?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareArray applicationActivities:nil];
controller.excludedActivityTypes = #[];
[self presentViewController:controller animated:YES completion:nil];
}
Its working but opening the location in apple maps.
Is there a way I can open the location in Google maps.
P.S- I have not tried whatsApp i have only tested for facebook.
If you want to open a Google Maps URL in your Google Maps iOS app, you can use comgooglemapsurl://maps.google.com/?q=%f,%f. If you want to show it in browser, you can do https://maps.google.com/?q=%f,%f.
Sample code:
-(void)testURL:(CLLocation*)location {
NSArray *shareArray;
if ([[UIApplication sharedApplication] canOpenURL:[[NSURL alloc] initWithString:#"comgooglemaps://"]]) {
shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:#"comgooglemapsurl://maps.google.com/?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];
} else {
shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:#"https://maps.google.com/?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];
}
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareArray applicationActivities:nil];
controller.excludedActivityTypes = #[];
[self presentViewController:controller animated:YES completion:nil];
}

Unable to added Facebook and Twitter to UIActivityViewController

Trying to share application on social median, and email, and message.
Since Email and message is working fine for me.
But Facebook,and twitter is not all showing to UIActivityViewController
Below is code which i try.
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePostToFacebook,
UIActivityTypePostToTwitter];
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:#[string, URL]
applicationActivities:nil];
activityViewController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityViewController
animated:YES
completion:^{
}];
- (id)activityViewController:(UIActivityViewController *)activityViewController
itemForActivityType:(NSString *)activityType
{
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
return NSLocalizedString(#"calling facebook", );
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
return NSLocalizedString(#"calling twitter", );
} else {
return nil;
}
}
#All
Please let me know what i need to do.
For that just create one class for that like this.
SharingActivityProvider.h
#import <Foundation/Foundation.h>
#interface SharingActivityProvider : UIActivityItemProvider
#end
**SharingActivityProvider.m**
#import "SharingActivityProvider.h"
#implementation SharingActivityProvider {
}
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
// Create the default sharing string
NSString *shareString = #"";
// customize the sharing string for facebook, twitter, weibo, and google+
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
shareString = [NSString stringWithFormat:#"Attention Facebook:%#", shareString];
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
shareString = [NSString stringWithFormat:#"Attention Twitter:%#", shareString];
} else if ([activityType isEqualToString:UIActivityTypePostToWeibo]) {
shareString = [NSString stringWithFormat:#"Attention Weibo:%#", shareString];
}
return shareString;
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return #"";
}
#end
Then after just use below code, suppose button action.
-(IBAction)shareAppTapped:(id)sender{
SharingActivityProvider *sharingActivityProvider = [[SharingActivityProvider alloc] init];
NSArray *activityProviders = #[sharingActivityProvider,#"what ever text"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityProviders applicationActivities:nil];
// tell the activity view controller which activities should NOT appear
activityViewController.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:activityViewController animated:YES completion:nil];
// [self.btnShareApp setBackgroundColor:OnebackgroundColorTable];
}
One mistake here is exclude activities also have facebook and twitter. Hence it will not show by any means.
Note excludedActivityTypes should be which you does not need in controller.
For example it should be:
NSArray *excludeActivities = #[UIActivityTypePostToWeibo,
UIActivityTypeMessage,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo];

Quirk in UIActivityViewController integration

I integrated a sharing option into my app and everything seems fine, basically I excluded every type of UIActivity except for Message, Twitter, and Facebook, and when I tested to see if it functions, what I see in the text box is
"I got a new highscore!
com.apple.UIKit.activity.Message
com.apple.UIKit.activity.PostToFacebook
com.apple.UiKit.activity.PostToTwitter".
and the text appears in each of activities.
Is there anyway to remove the text, or is it supposed to be that way?
Here is a method in my MainViewController which presents the UIActivityViewController.
-(void)sharedView {
APActivityProvider *APActivityPro = [[APActivityProvider alloc] init];
NSArray *activites = #[APActivityPro,UIActivityTypeMessage, UIActivityTypePostToFacebook, UIActivityTypePostToTwitter];
activityController = [[UIActivityViewController alloc] initWithActivityItems:activites applicationActivities:nil];
activityController.excludedActivityTypes = #[UIActivityTypePostToWeibo,
UIActivityTypeMail,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
UIActivityTypeAirDrop];
[self presentViewController:activityController animated:YES completion:nil];
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed)
{
if (completed)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:NSLocalizedString(#"Post Sent!",#"the confirmation of the sent message/post")
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK",#"done")
otherButtonTitles:nil];
[alert show];
}
}
];
}
And also my code in my APActivityProvider.m file.
-(id) activityViewController:(UIActivityViewController*)activityViewController
itemForActivityType:(NSString *)activityType
{
if ([activityType isEqualToString:UIActivityTypeMessage])
return NSLocalizedString(#"I got a new highscore!",#"Comment for message");
if ([activityType isEqualToString:UIActivityTypePostToFacebook])
return NSLocalizedString(#"I got a new highscore!",#"Comment for Facebook");
if ([activityType isEqualToString:UIActivityTypePostToTwitter])
return NSLocalizedString(#"I got a new highscore!",#"Comment for twitter");
return nil;
}
- (id) activityViewControllerPlaceholderItem:(UIActivityViewController *)
activityViewController
{
return #"";
}
It would appear you are using the API incorrectly. Specifically:
NSArray *activites = #[APActivityPro,UIActivityTypeMessage, UIActivityTypePostToFacebook, UIActivityTypePostToTwitter];
activityController = [[UIActivityViewController alloc] initWithActivityItems:activites applicationActivities:nil];
Activity Items are your content (Strings, Images, etc) while applicationItems are the custom activity options you add to the default system ones (something you code such as an open in app store activity). You do not need to tell the UIActivityViewController what system activities you want. All are enabled by default.
For an example of how to use this API, I have included the following:
NSNumber *AppStoreID = [NSNumber numberWithInt:550008982];
NSArray *activityItems =
#[ AppStoreID ];
NSArray *applicationActivities =
#[ [ATFAppStoreActivity alloc] ];
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
[self presentViewController:activityViewController animated:YES completion:nil];
Here, I have my subclassed UIActivity (ATFAppStoreActivity) that takes an NSNumber to display the App Store page for that app.

iOS Memory Leak with Activity View

I just discovered a memory leak in my app but I'm not really sure how to go about fixing it. It involves an activity view which is used to share the url of the current article being viewed from an rss feed. I'm not really sure why the leak is happening. Any ideas or advice?
The method in question for the iPhone version is:
- (void) showMenu
{
NSURL *urlToShare = hackyURL;
NSArray *activityItems = #[urlToShare];
TUSafariActivity *activity = [[TUSafariActivity alloc] init];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:#[activity]];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
EDIT: I've fixed the iPhone leak by changing the above code to this:
__block UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:#[activity]];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:YES completion:^{activityVC.excludedActivityTypes = nil; activityVC = nil;}];
The iPad version is essentially the same except that it uses a popover to display the activity view.
- (void)showMenu
{
NSURL *urlToShare = hackyURL;
NSArray *activityItems = #[urlToShare];
TUSafariActivity *activity = [[TUSafariActivity alloc] init];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:#[activity]];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];
if ([popover isPopoverVisible])
{
[popover dismissPopoverAnimated:YES];
popover = nil;
}
else
{
self.popover = [[UIPopoverController alloc]initWithContentViewController:activityVC];
[self.popover presentPopoverFromBarButtonItem:systemAction permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
I've fixed the iPhone leak by changing the above code to this:
__block UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:#[activity]];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:YES completion:^{activityVC.excludedActivityTypes = nil; activityVC = nil;}];
but I can't figure out how to fix the leak for the popover on iPad.
if ([self.popover isPopoverVisible])
{
[self.popover dismissPopoverAnimated:YES];
self.popover = nil;
}
else
{
self.popover = [[UIPopoverController alloc]initWithContentViewController:activityVC];
[self.popover presentPopoverFromBarButtonItem:systemAction permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Hope it will resolve your issue.

Resources