in my application want to open custom pop up in UIActivityViewController. So i don't want to open default sharing pop up in facebook. So how to dismiss that pop up or how to block to open that pop up in iOS.
Please give me solution ...
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismissPopup) name:dismissMJPopUp object: nil];
//ReferFriendVC *okpopup=[[ReferFriendVC alloc]initWithNibName:#"ReferFriendVC" bundle:nil];
// [self presentPopupViewController:okpopup animationType:MJPopupViewAnimationSlideBottomTop];
UIPopoverController *popup;
MyActivityItemProvider *message = [[MyActivityItemProvider alloc] init];
NSArray *activityItems;
UIImage *myImage=[UIImage imageNamed:#"3.png"];
activityItems = #[message, myImage];
NSArray * applicationActivities = nil;
UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = #[
UIActivityTypePostToWeibo,
UIActivityTypeAssignToContact,
UIActivityTypeAirDrop,
UIActivityTypeAddToReadingList,
UIActivityTypeCopyToPasteboard,
UIActivityTypeSaveToCameraRoll,
UIActivityTypePrint,
UIActivityTypePostToFlickr,UIActivityTypePostToTencentWeibo // Whatever you want to exclude
];
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0")){
activityViewController.popoverPresentationController.sourceView =
self.view;
}
if(isiPhone)
{
[self presentViewController:activityViewController animated:YES completion:nil];
}
else{
popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[popup presentPopoverFromRect:CGRectMake(0, screenheight, 768, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
[activityViewController setCompletionWithItemsHandler:^(NSString *act, BOOL completed, NSArray *returnedItems, NSError *activityError)
{
NSLog(#"act type %#",act);
NSString *ServiceMsg = nil;
if ( [act isEqualToString:UIActivityTypeMail] )
ServiceMsg = #"Mail sent";
NSLog(#"mail sent");
if ( [act isEqualToString:UIActivityTypeAssignToContact] )
ServiceMsg = #"Post on twitter, ok!";
if ( [act isEqualToString:UIActivityTypePostToFacebook] )
ServiceMsg = #"Post on facebook, ok!";
[popup dismissPopoverAnimated:YES];
}];
And in myActivityItemProvide.h
#import "MyActivityItemProvider.h"
#implementation MyActivityItemProvider
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
NSLog(#"mail method called ");
//
if([AppDelegate NetworkRechability])
{
// FrindListVC *leavefeed=[[FrindListVC alloc]initWithNibName:#"FrindListVC" bundle:nil];
// [self.navigationController pushViewController:leavefeed animated:YES];
FBSDKAppInviteContent *content1 =[[FBSDKAppInviteContent alloc] init];
content1.appLinkURL = [NSURL URLWithString:#"https://fb.me/4931252562362626805"];
//optionally set previewImageURL
content1.appInvitePreviewImageURL = [NSURL URLWithString:#"http://files.parsdrterfsdfetfss.com/79580e8563-55656cc-456455f2-a20f-7f69e783b14d/tfss-f9e2626e-dfsdfsfsdfsdf519c-4ca3-ae47-015ffeaad0f7-fbinvite-01.png"];
// present the dialog. Assumes self implements protocol `FBSDKAppInviteDialogDelegate`
[FBSDKAppInviteDialog showWithContent:content1
delegate:self];
// [[[self parentViewController] parentViewController] presentViewController:activityViewController animated:YES completion:nil];
// activityViewController.view.hidden=YES;
}
else
{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Internet Not Available" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
[SVProgressHUD dismiss];
}
}
return #"No provider";
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error
{
NSLog(#"error %#",error);
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)result
{
// NSLog(#"result %#",result);
}
- (id) activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController { return #""; }
#end
You can exclude or block to open default Facebook sharing in UIActivityViewController using below code:
activityViewController.excludedActivityTypes = [UIActivityTypePostToFacebook]
Related
I have a code that I modified to pull data from an external JSON file. There are two NSArrays. One for the image and one for color. Then, when a particular array is pressed it opens a webviewcontroller. I got it to work perfectly. Here is the problem. I want to be able to modify the JSON anytime I want externally and have the app update the information but since the NSArray information is hardcoded I don't know how to remove an array if I remove an objectforkey from the JSON. Any help would be appreciated.
The code to call the images and colors is:
- (IBAction)onclick:(id)sender {
NSArray *images = #[
[UIImage imageNamed:[NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"PhoneUrl"]]],
[UIImage imageNamed:[NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"TextUrl"]]],
[UIImage imageNamed:[NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"MailUrl"]]]
];
NSArray *colors = #[
[UIColor [NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"PhoneColor"]],
[UIColor [NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"TextColor"]]],
[UIColor [NSString stringWithFormat: #"%#",[dataDictionary objectForKey:#"MailColor"]]],
];
Sidebar *callout = [[Sidebar alloc] initWithImages:images borderColors:colors];
callout.delegate = self;
[callout show];
}
Then when pressed it calls the following:
- (void)sidebar:(Sidebar *)sidebar didTapItemAtIndex:(NSUInteger)index {
self.webViewController = [[PBWebViewController alloc] init];
PBSafariActivity *activity = [[PBSafariActivity alloc] init];
self.webViewController.applicationActivities = #[activity];
self.webViewController.excludedActivityTypes = #[UIActivityTypeMail, UIActivityTypeMessage];
NSLog(#"Tapped item at index %lu",(unsigned long)index);
if (index == 0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[dataDictionary objectForKey:#"PhoneWeb"]]];
[sidebar dismissAnimated:YES completion:nil];
}
if (index == 1) {
if(![MFMessageComposeViewController canSendText]) {
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
return;
}
NSArray *recipents = #[[dataDictionary objectForKey:#"TextWeb"]];
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[[messageController navigationBar] setTintColor:[UIColor whiteColor]];
[self presentViewController:messageController animated:YES completion:nil];
[sidebar dismissAnimated:YES completion:nil];
}
if (index == 2) {
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
[[mailer navigationBar] setTintColor:[UIColor whiteColor]];
mailer.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObjects:[dataDictionary objectForKey:#"MailWeb"], nil];
[mailer setToRecipients:toRecipients];
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failure"
message:#"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
[sidebar dismissAnimated:YES completion:nil];
}
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];
IOS 7, 8 how to post messages, images on Facebook, Twitter community page's wall. I tried with SLComposeViewController and it is possible to post in logged in user's wall but didn't see how to post to a Facebook or Twitter community or page wall.
You can do this with UIActivityViewController.Create a button outlet And write the below code in IBAction.
- (IBAction)Share:(id)sender{
NSString *shareString=[NSString stringWithFormat:#"Write here what you want to share"];
NSArray * itemsArray = #[[NSString stringWithFormat:#"%#",shareString]];//if you want to share image here pass url of image in the array.
NSArray * applicationActivities = nil;
UIActivityViewController * AVC = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];
[self presentViewController:AVC animated:YES completion:nil];
[AVC setCompletionHandler:^(NSString *act, BOOL done)
{
NSString *ServiceMsg = nil;
if([act isEqualToString:UIActivityTypeMail]) {
ServiceMsg = #"Mail sent!";
} else if([act isEqualToString:UIActivityTypePostToTwitter]) {
ServiceMsg = #"Shared on twitter!";
} else if([act isEqualToString:UIActivityTypePostToFacebook]) {
ServiceMsg = #"Shared on facebook!";
} else if([act isEqualToString:UIActivityTypeMessage]) {
ServiceMsg = #"SMS sent!";
} else if([act isEqualToString:UIActivityTypeAddToReadingList]) {
ServiceMsg = #"Added to Reading List";
} else if([act isEqualToString:UIActivityTypeCopyToPasteboard]){
ServiceMsg = #"Link Copied";
}
if ( done )
{
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:#"" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil];
[Alert show];
}
}];
}
Hope it will help you.
How to know which icon is clicked in UIActivityViewController before activityController setCompletionHandler:^(NSString *activityType, BOOL completed) is called ?
I want to share different text for sharing with twitter and facebook.
-(IBAction)btnSharePressedFromOffersDetail:(id)sender
{
NSString *posturl= #"facebook or twitter";
UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]init];
NSArray *Itemsarray=#[posturl,printData];
UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:Itemsarray applicationActivities:nil];
[self presentViewController:activityController
animated:YES completion:nil];
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed)
{
NSLog(#"Activity = %#",activityType);
NSLog(#"Completed Status = %d",completed);
if (completed)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:#"Thanks for sharing!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
}
}];
}
If your goal is to use a different text for Twitter or Facebook, it's the responsability of your shared Model who implement the UIActivityItemSource protocol.
- (id) activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
if([activityType isEqualToString:UIActivityTypePostToFacebook]) return #"Facebook text";
else if([activityType UIActivityTypePostToTwitter]) return #"Twitter text";
else return #"Default text";
}
You can go with link given below, there is tutorial which might helps you.
https://www.albertopasca.it/whiletrue/objective-c-custom-uiactivityviewcontroller-icons-and-text/
and http://nshipster.com/uiactivityviewcontroller/
This is some code from my sms plugin for phonegap. I'm trying to make callbacks work properly: https://github.com/aharris88/phonegap-sms-plugin/issues/11
Here's the code I'm working on. You can see that I get the callback function at the beginning of the send method like this:
NSString* callback = command.callbackId;
Then I present an MFMessageComposeViewController and I need to call that callback when it finishes. So I'm using the messageComposeViewController:didFinishWithResult:, but how can I access that callback function that I need to call?
#import "Sms.h"
#import <Cordova/NSArray+Comparisons.h>
#implementation Sms
- (CDVPlugin *)initWithWebView:(UIWebView *)theWebView {
self = (Sms *)[super initWithWebView:theWebView];
return self;
}
- (void)send:(CDVInvokedUrlCommand*)command {
NSString* callback = command.callbackId;
if(![MFMessageComposeViewController canSendText]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Notice"
message:#"SMS Text not available."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
return;
}
MFMessageComposeViewController* composeViewController = [[MFMessageComposeViewController alloc] init];
composeViewController.messageComposeDelegate = self;
NSString* body = [command.arguments objectAtIndex:1];
if (body != nil) {
[composeViewController setBody:body];
}
NSArray* recipients = [command.arguments objectAtIndex:0];
if (recipients != nil) {
[composeViewController setRecipients:recipients];
}
[self.viewController presentViewController:composeViewController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
#pragma mark - MFMessageComposeViewControllerDelegate Implementation
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
int webviewResult = 0;
CDVPluginResult* pluginResult = nil;
switch(result) {
case MessageComposeResultCancelled:
webviewResult = 0;
break;
case MessageComposeResultSent:
webviewResult = 1;
break;
case MessageComposeResultFailed:
webviewResult = 2;
break;
default:
webviewResult = 3;
break;
}
[self.viewController dismissViewControllerAnimated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
if (webviewResult == 1) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:#"Arg was null"];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:callback];
}
#end
You'll want to store the callback ID as a property on the class.
#interface Sms
#property (nonatomic, strong) NSString *callbackId
#end
And then store it when you are in your send method.
- (void)send:(CDVInvokedUrlCommand*)command {
self.callbackId = command.callbackId;
You can then access it again from your delegate method:
NSString *callbackId = self.callbackId;
You should be good to go.