Unable to Share a URL through Bluetooth(UIActivityViewController) - ios

I'm trying to share a URL so that URL should be opened in Safari or any web browser but unable to do so. I have Sent that to my MAC and MAC opening it as text file and then by clicking on that i'm going to safari but in case of iPhone i'm struggling to open it.In case of NSURL my app crashes with some exception. Here is my code
NSString *url=#"www.google.com";
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:#[url] applicationActivities:nil];
// Exclude all activities except AirDrop.
NSArray *excludedActivities = #[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
UIActivityTypePostToWeibo,
UIActivityTypeMessage, UIActivityTypeMail,
UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;
// Present the controller
[self presentViewController:controller animated:YES completion:nil];

Change this line:
NSString *url=#"www.google.com";
to:
NSURL *url= [NSURL URLWithString:#"https://www.google.com"];
If this doesn't work for you because of a crash it's likely a problem elsewhere, but make the crash report available and maybe I can help.

Related

How to share Deeplinking url via Email

I tried to share Url, for instance,deeplink:// via default iphone Email.But unfortunately,the link doesn't turn as hyperlink mode so that it can be clickable and directed to the specified location.So please kindly help me for the below code.
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"deeplink://"]];
NSArray * activityItems = #[url];
NSArray * applicationActivities = nil;
NSArray * excludeActivities = #[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeMessage];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityController animated:YES completion:nil];
Custom URI schemes are not a valid solution for this. As you discovered, they are not recognized as links in many situations, but there are other more serious issues too. Read this answer for more information

Add to iCloud Drive with UIActivityViewController

I would like to use UIActivityViewController's "Add to iCloud Drive" action pictured here to upload a file that I store on the iOS device:
Currently in my custom UIActivityItemProvider class I have my - (id)item method returning this:
[NSURL fileURLWithPath:fullPath];
FullPath is the path to the file that I am creating and want to upload to iCloud drive. It works when I click "Add to Notes", the mail activity, or my custom activity but it does not for iCloud drive. Instead of using this file, it creates a default file with the subject I am using for the email activity which is "Attached is a file." as the file contents. Here is the code I am using to present the UIActivityViewController:
CustomActivity * customActivity = [[CustomActivity alloc]init];
CustomItemProvider *itemProvider = [[CustomItemProvider alloc] initWithPlaceholderItem:_itemsArray];
NSArray *activityItems = [NSArray arrayWithObjects:itemProvider, NSLocalizedString(#"Attached is a file.", nil), nil];
UIActivityViewController *avc = [[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:#[customActivity]];
float iOSVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (iOSVersion < 9.0)
{
avc.excludedActivityTypes = #[UIActivityTypePostToFacebook, UIActivityTypeAirDrop, UIActivityTypeCopyToPasteboard, UIActivityTypeMessage, UIActivityTypePostToFlickr, UIActivityTypePostToTwitter, UIActivityTypePostToVimeo, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, UIActivityTypePostToTencentWeibo,UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList];
}
else
{
avc.excludedActivityTypes = #[UIActivityTypePostToFacebook, UIActivityTypeAirDrop, UIActivityTypeCopyToPasteboard, UIActivityTypeMessage, UIActivityTypePostToFlickr, UIActivityTypePostToTwitter, UIActivityTypePostToVimeo, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, UIActivityTypePostToTencentWeibo,UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList, UIActivityTypeOpenInIBooks];
}
[self presentViewController:avc animated:YES completion:nil];
Code seems to correct. But iCloud option will be added only when :
User must login in iCloud in Settings.
You have something valid info like you can upload on iCloud. (If you are using any url in sharing then iCloud option is not shown in ActivityController)
It support those type of data it can allow you to upload, like notes, photos, contact, calendar event, etc.
I have tried this :
NSString *strTextToShare = #"Hi... Friends";
UIImage *imgToShare = [UIImage imageNamed:#"wall1.png"];
NSURL *urlToShare = [NSURL URLWithString:#"https://www.apple.com"];
UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:#[strTextToShare, /*imgToShare, urlToShare*/] applicationActivities:nil];
[self presentViewController:shareController animated: YES completion: nil];
In above, if I tried to add URL then iCloud not shown. And also
Note : At a time if only one item you share, then only iCloud will shown.

When Called From UIActivityViewController WhatsApp Freezes After a Recipient Is Selected

I am using UIActivityViewController to share my iOS app.
When WhatsApp is selected from the list of options, it takes me to the proper screen. I can move around, and all the buttons work.
However, once I select a recipient, WhatsApp freezes.
Does anyone know what's going on here? Has anyone encountered this bug before?
EDIT (Code Added)
Here's the code I'm using to call the UIActivityViewController:
- (void) sharePressed:(UIBarButtonItem *)sender {
NSString* shareText = #"Hello World!";
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:#[shareText] applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
NSLog(#"This method ran: sharePressed");
}
It's as basic as it gets. It works for everything except WhatsApp.
try this code
- (IBAction)shareButton:(UIBarButtonItem *)sender
{
NSString *textToShare = #"Look at this awesome website for aspiring iOS Developers!";
NSURL *myWebsite = [NSURL URLWithString:#"http://www.codingexplorer.com/"];
NSArray *objectsToShare = #[textToShare, myWebsite];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}
I think the error was actually an internal problem with either whatsapp or UIActivityViewController because my other apps that use UIActivityViewController couldn't share on whatsApp last night. This morning though, even though I didn't change anything in my code, everything works perfectly!
I think is a bug in WhatsApp after yesterday update.
Update: You can send an NSUrl instead of NSString.

ios plugin com.google.Gmail.ShareExtension invalidated

I am trying to share Text in Gmail with UIActivityViewController but i am getting this message in log.
plugin com.google.Gmail.ShareExtension invalidated.
Due to this i am not getting mail in my Gmail inbox.
I have also tried to add entry of APPTransportSecurity in .plist
I have also followed all the steps which said in plugin-com-apple-share-facebook-post-invalidated question.
But still i am getting message in my log and not able to get mail in Gmail inbox.
Here is my code for UIActivityViewController implementation.
NSString *P_Name =[NSString stringWithFormat:#"Product Name :- %# \n Offers :- %#",[[arryDetail objectAtIndex:selectedindex] objectForKey:#"productname"],[[arryDetail objectAtIndex:selectedindex] objectForKey:#"offers"]];
NSArray *objectsToShare = #[P_Name];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludedActivities = #[UIActivityTypePostToTwitter,
UIActivityTypePostToFacebook,
UIActivityTypePostToWeibo,
UIActivityTypeMessage,
UIActivityTypeMail,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypeAirDrop,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo];
activityVC.excludedActivityTypes = excludedActivities;
[self presentViewController:activityVC animated:YES completion:nil];
Note:- I am successfully able to send message in whatsapp with this warning.
plugin net.whatsapp.WhatsApp.ShareExtension invalidated

Sharing a file through my ios Application with UIActivityViewController

I have some files that want to share with any application. I use this code
var fileDAta = NSData.FromFile(path);
UIActivityViewController activityViewController = new UIActivityViewController
(new NSObject[]{ fileDAta }, null); //(items, null);
PresentViewController(activityViewController,true,null);
As you see, it should be more application but as a default, there is just the Mail App. it is the same for real device.. (I also installed Gmail and Outlook but there is not on the list or on the more list)
Anyway,when i select the Mail, it cannot be attached ..
What I should change?
Use the following code for sharing but remember respective applications(gmail,twitter etc) for sharing must be installed on your device and configured.
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems: fileDAta applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll]; //or whichever you don't need
[self presentViewController:activityVC animated:YES completion:nil];

Resources