How to share a contact from iOS app to Whatsapp? - whatsapp

Sharing .vcf to WhatsApp using UIActivityViewController fails by showing plugin net.whatsapp.WhatsApp.ShareExtension invalidated error
Sharing image or text is working using UIActivityViewController, But sharing .vcf is not working with whatsapp (working fine for mail/message/messenger etc).
NSData *pVcfData = [CNContactVCardSerialization dataWithContacts:[NSArray arrayWithObject:pContact] error:&pError]; // creating contact data from CNContactVCardSerialization
NSURL *pFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:pFileNameWithAllowedCharacters]]; // wrote the data to file
NSError *pWriteError = nil;
if ([pVcfData writeToURL:pFileURL options:NSDataWritingAtomic error:&pWriteError])
{
NSArray *pActivityItems = #[pFileURL]; // passed the file URL as ActivityItem for UIActivityViewController
UIActivityViewController *pActivityVC = [[UIActivityViewController alloc] initWithActivityItems:pActivityItems applicationActivities:nil];
[pActivityVC setValue:pContactName forKey:#"subject"];
[self presentViewController:pActivityVC animated:YES completion:nil];
}
Is there any other method to share contact to whatsapp other than .vcf. Please share any suggestion.

Related

How can I add 'Follow us on facebook' button to an iOS app?

I've about completed my iOS app but only need to add two buttons:
Follow us on facebook
Follow us on twitter
I assumed I would find a couple of simple examples here, but was surprised to find no answer to this at all (yet).
I'm pretty sure I could spend the next few hours trying to figure it out, but thought I'd reach out for a little time-saving help.
Just looking for the code to go behind a button on a view controller (XCode 4.5.1, iOS 6).
I assume the only variable I might need to supply is the company's facebook account name.
Any suggestions? (Thanks in advance!)
First, the URL schem for Facebook: fb://profile/<yourpageid> (source). A URL with this structure will open the Facebook app, if it is installed.
More on iOS URL schemes.
When your button is tapped, you can check if the Facebook is installed:
-(IBAction)fbButtonTap:(id)sender {
NSURL *fbURL = [[NSURL alloc] initWithString:#"fb://profile/<yourpageid>"];
// check if app is installed
if ( ! [[UIApplication sharedApplication] canOpenURL:fbURL] ) {
// if we get here, we can't open the FB app.
fbURL = ...; // direct URL on FB website to open in safari
}
[[UIApplication sharedApplication] openURL:fbURL];
}
For twitter, you follow the same basic steps. The Twitter URL scheme for iOS is twitter://user?id=12345 or twitter://user?screen_name=yourname (source). Again, if the Twitter app is not installed, you have open the twitter profile in safari.
As for taking direct actions, I do not think you can do that, since there is no inherent knowledge about any other applciation installed on the device. The best I think you can do is direct users to each respective account.
You could use SLRequest have someone follow you. This will only work on iOS 6 though, on iOS 5 Twitter works but not Facebook.
An example of SLRequest for someone to follow you on Twitter, make sure this is called on the background thread:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:#"Your twitter name" forKey:#"screen_name"];
[tempDict setValue:#"true" forKey:#"follow"];
SLRequest *followRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:#"https://api.twitter.com/1/friendships/create.json"] parameters:tempDict];
[followRequest setAccount:twitterAccount];
[followRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:#"HTTP response status: %i", [urlResponse statusCode]];
NSLog(#"%#", output);
if (error) {
dispatch_async(dispatch_get_main_queue(), ^{
//Update UI to show follow request failed
});
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
//Update UI to show success
});
}
}];
}
}
}];
And for Facebook you just have to change some of it and look at their API and change the request URL.
this is my code for show people to like the community page of my app.
you can add the _webview where you want to show inside the code.
facebook gives the code for showing the page inside webview.
-(void)likeus
{
_webview =[[UIWebView alloc] initWithFrame:CGRectMake(14,94, 292, 250)];
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//Load web view data
NSString *strWebsiteUlr =#"http://www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Fenbuyukkim&width=292&height=258&show_faces=true&colorscheme=dark&stream=false&border_color&header=false&appId=433294056715040";
// Load URL
//Create a URL object.
NSURL *url = [NSURL URLWithString:strWebsiteUlr];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[_webview loadRequest:requestObj];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:_webview
action:#selector(removeFromSuperView)
forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(270.0, 80.0, 30.0, 30.0);
[button setBackgroundImage:[UIImage imageNamed:#"cross.png"] forState:UIControlStateNormal];
[_webview addSubview:button];
}
I am not sure if this is what you are looking for, but I think I found the solution, here at stack overflow on another thread.
Take a look at this thread:
Adding the Facebook Like Button in an iPhone App
Hope that helps you!

ios - Showing a Download progress UIViewController

After implementing the HCDownload for iOS into my app I am successfully able to display the downloading progress of a file.
The problem is that the guy who wrote it, didn't use Xcode to write the module, so even though it should, it does not really work nice when trying to integrate with a project.
These are the main issues I have with it:
If you do a [self.navigationController pushViewController:dlvc animated:YES]; or a [self presentViewController: animated: completion:]; then it shows when it is initiated. I can get out of it, by navigating back, but then when I return to it, it is blank - so I cannot see what the progress is of the download. The download however keeps going, because it appears in my documents folder. ( I use ASIHTTP framework)
Now I am working with storyboard in this project, and because this does not come with a XIB file I thought (which has kinda worked in the past) I could just have a UITableViewController and have this as its Custom Class, but it does not play ball.
Is there a XIB based Download manager FrameWork that someone can point me too, or has anyone had luck with this one?
PS I know Storyboards do not use XIB files, but that way it is easier to integrate into storyboard than no UI files at all:-)
Kind thanks for the tips.
Edit
Here is the code where I implement it:
HCDownloadViewController *dlvc = [[HCDownloadViewController alloc] init];
dlvc.delegate = self;
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
dlvc.downloadDirectory = documentDirectory;
NSString *fileSave = [_streamingURL lastPathComponent];
NSURL *url = [NSURL URLWithString:_streamingURL];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[dlvc downloadURL:url userInfo:nil];
// Add your filename to the directory to create your saved pdf location
NSString *pdfLocation = [documentDirectory stringByAppendingPathComponent:fileSave];
NSString *cachesDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
// Add your filename to the directory to create your temp pdf location
NSString *tempPdfLocation = [cachesDirectory stringByAppendingPathComponent:fileSave];
if (!networkQueue) {
networkQueue = [[ASINetworkQueue alloc] init];
}
failed = NO;
[request setTemporaryFileDownloadPath:tempPdfLocation];
[request setDownloadDestinationPath:pdfLocation];
[request setDownloadProgressDelegate:progressBar];
[request setShowAccurateProgress:YES];

iOs Custom scheme in MFMailComposeViewController

I'm trying to send via MFMailComposeViewController a custom url scheme so that the receipient could tap on the embedded link and open my application on his iphone.
So far the receipient gets an email but nothing happens when he taps on the LINK.
here is the code:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet
[picker setSubject:#"Incoming task"];
// Fill out the email body text
NSString * types = #"";
for(NSString *type in task.location_types){
types = [types stringByAppendingFormat:#"%#|",type];
}
if(types.length > 1){
types = [types substringToIndex:types.length - 1];
}
NSString *desc = [task.description stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *link = [NSString stringWithFormat:#"helpy://?taskid=%d&desc=%#&types=%#\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:#"TAP HERE<script type=\"text/javascript\" charset=\"utf-8\">function doSomething() { window.location = \"%#\;return false;}</script>",link];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[controller presentModalViewController:picker animated:YES];
[picker release];
helpy://?taskid=..... is my custom registered URL Scheme and if I type it from the address bar of the browser it opens up my application on the iPhone.
For some reason when this link is embedded into email, tapping it does not do anything.
Any help?
thanks
I highly doubt that Mail will execute JavaScript on iOS (even on the desktop I highly doubt it, but haven't tried it though). Simply set the URL as the href attribute of your hyperlink and everything should work fine. Any reason why you want to do it with JavaScript? I'm just curious ;-)
NSString *link = [NSString stringWithFormat:#"helpy://?taskid=%d&desc=%#&types=%#\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:#"TAP HERE", link];

SoundCloud API iOS, no sharing - only listening

I got a website where I make playlists with SoundCloud. Now I want to make an app for iPhone so the users can listen to the songs there as well.
http://developers.soundcloud.com/docs/api/ios-quickstart
In the example in the link the users have to sign in to listen and share, but I want my users only to listen. Is there a way around so they don't have to sign in?
Create a page that outputs the playlist in JSON, then in xcode create a class that downloads the JSON for the track dictionaries and play the downloaded content using AVPlayer (or AVQueuePlayer if you're playing the whole list).
Here's some abstract code:
playlistDownloader.m
- (void)downloadPlaylist{
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_sync(concurrentQueue, ^{
NSURL *url = [NSURL URLWithString:#"http://www.yourwebsite.com/playlist.json?id=1"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
id trackData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
if (!error) {
tempTrackArray = trackData;
} else {
NSLog(#"Playlist wasn't able to download");
}
});
}
tempTrackArray would be a property declared in the class.
Then in your player, you'd do something like this:
audioPlayer.m
- (void)instanciateAudioPlayer
{
NSDictionary *trackDictionary = [playListDownloader.tempTrackArray objectAtIndex:0];
NSString *urlString = [trackDictionary objectForKey:#"stream_url"];
AVAsset *asset = [AVAsset assetWithURL:streamURL];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[avPlayer initWithPlayerItem:playerItem];
}
This is some really rough code but its the general gist of what you're trying to do. Should get you going in the right direction.
Trying the soundcloud quickstart I realised that your stream url needs to begin with https rather than http. Also you need to add your client id from your sound cloud app to the stream url:
NSDictionary *trackDictionary = [playListDownloader.tempTrackArray objectAtIndex:0];
NSString *streamURL = [trackDictionary objectForKey:#"stream_url"];
streamURL = [streamURL stringByReplacingOccurrencesOfString:#"http" withString:#"https"];
NSString *urlString = [NSString stringWithFormat:#"%#?client_id=%#", streamURL, #"a8e117d3fa2121067e0b29105b0543ef"];
From there you just setup the AVPlayer:
self._avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:urlString]];
[self setupLayer:clayer];
[self._avPlayer play];
Everything should work fine. Hope it helps

Export image to Instagram - iPhone

I have an image and I want to export it to Instagram, so I can post it.
The code I'm using is:
NSURL *instagramURL = [NSURL URLWithString:#"instagram://location?id=1"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:#"Image.igo"];
UIImage *image = [UIImage imageNamed:#"01.png"];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath];
NSLog(#"%#",imageUrl);
UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init];
docController.delegate = self;
docController.UTI = #"com.instagram.exclusivegram";
docController.URL = imageUrl;
//[docController setURL:imageUrl];
[docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
When I run the app, the App shows the button written "Instagram" its icon, but when I touch it, the button disappear, and nothing happens. The app didn't crash, but nothing happen.
What I missed in my code ?
Regards
Bruno
I guess the problem is you do not retain the UIDocumentInteractionController. Make an ivar for it in your class.
Make sure the method documentInteractionController:didEndSendingToApplication: is called on the delegate.
Also check out the Instagram documentation: http://instagram.com/developer/iphone-hooks/
When triggered, Instagram will immediately present the user with our
filter screen. The image is preloaded and sized appropriately for
Instagram. Other than using the appropriate image format, described
above, our only requirement is that the image is at least 612px tall
and/or wide. For best results, Instagram prefers opening a JPEG that
is 612px by 612px square. If the image is larger, it will be resized
dynamically.
To verify that Instagram is installed check for the URL instagram://app. The URL instagram://location?id=LOCATION_ID is intended for location feeds only!