Our two teams are developing same app: adroid team and iOS team. Android team was able to do text + photo sharing. Simple post with text is done normally but text + image requires google+ app and the code that opens small center'ed web view looks like this:
Intent shareIntent = ShareCompat.IntentBuilder.from(act)
.setText(message).setStream(uri).setType("image/jpeg")
.getIntent().setPackage("com.google.android.apps.plus");
act.startActivityForResult(shareIntent, SocialNetworksConstants.GOOGLE_POST_REQUERST);
However, I can't find anything similar in the newest Google+ iOS sdk. GPPShareBuilder protocol only has:
- (id<GPPShareBuilder>)setPrefillText:(NSString *)prefillText;
and
- (id<GPPShareBuilder>)setTitle:(NSString *)title
description:(NSString *)description
thumbnailURL:(NSURL *)thumbnailURL;
Has anybody faced this problem?
UPDATE: Here's a link to solution for Android. It looks like Android has some "ShareCompat" Android native library that extends functionality for sharing data between apps.
UPDATE2 Tried to use "setTitle:description:thumbnailURL:" with google+ sharing sample code in recent Google+ sdk. Tried to push NSURL of some image from bundle:
- (IBAction)shareButton:(id)sender{
...
if (title && description) {
//NSURL *imageUrl = [NSURL URLWithString:[deepLinkThumbnailURL_ text]];
NSString *imagePathString = [[NSBundle mainBundle] pathForResource:#"my_image" ofType:#"png"];
NSURL *imageUrl = [[NSURL alloc] initWithString:imagePathString];
shareBuilder = [shareBuilder setTitle:title
description:description
thumbnailURL:imageUrl]; // throw image path
}
However that didn't work out. Image placeholder is empty when google+ opens sharing window in safari. Only some external URL link is working.
Use this :
NSData *imageData = UIImagePNGRepresentation(myImage.image);
[(id< GPPNativeShareBuilder >)shareBuilder attachImageData:imageData];
Related
Im trying to Get Information About a Website like title (Like what you see in safari in the Tabs and Windows)and Description of that Website from its URL Without Using the WebKit Framework in Xcode and Displaying it on screen as text. I Just want to know have to obtain the title of the Website/Page that the URL Belongs to using Cocoa. Is There a Tutorial or Something. It will be a Big Help.
Try this:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString* title = [webView stringByEvaluatingJavaScriptFromString: #"document.title"];
navbar.title = title;
}
Taken from: http://blog.mcohen.me/2008/12/12/getting-the-title-of-a-web-view-in-cocoa-touch/
If you don't want to display the webview, make it hidden and use above delegate method to get what you want...
A way you could do it is by downloading the HTML content at the target url and parse it, for example using hpple.
Example (not tested):
NSURL *url = [NSURL URLWithString:#"http://..."];
//Only using this for simplicity of the example.
//You should really use an asynchronous method instead (see `NSURLSession`).
NSData *urlData = [NSData dataWithContentsOfURL:url];
//Parse HTML and search for title element
TFHpple *hppleParser = [[TFHpple alloc] initWithHTMLData:data];
TFHppleElement *titleElement = [hppleParser search:#"//title"][0];
NSString titleString = titleElement.text;
I have been drawing routes in iOS5, but as the app has to be upgraded to iOS6, it does not allow to draw routes between coordinate locations . I have searched a lot, but ended up in vain. Can anyone help me on which api to use in iOS6 since google maps doesnt support anymore ???
EDIT : I have used Google iOS SDK previously to plot the routes which will auto take care of the polylines. As far as I have searched, i will be able to redirect to browser to show routes and navigation. But i need to draw this in-app [ iOS6 ]. Does iOS6 automatically does the routing, if so can u pls share some code to get a gist of it. This code sample I used it in iOS5 using google maps
// over lay map to draw route
routeOverlayView = [[UICRouteOverlayMapView alloc] initWithMapView:routeMapView];
diretions = [UICGDirections sharedDirections];
UICGDirectionsOptions *options = [[UICGDirectionsOptions alloc] init];
//setting travel mode to driving
options.travelMode = UICGTravelModeDriving;
[diretions loadWithStartPoint:startPoint endPoint:endPoint options:options];
// Overlay polylines
UICGPolyline *polyline = [directions polyline];
NSArray *routePoints = [polyline routePoints];
NSLog(#"routePoints %#",routePoints);
[routeOverlayView setRoutes:routePoints];
I did route in my application. I used The Google Geocoding API (used for iOS 6 only) https://developers.google.com/maps/documentation/geocoding/
Something like this:
- (void) sendRequestForLat: (CGFloat) lat lon: (CGFloat) lon
{
NSString* request;
NSInteger zoom = 12;
NSString* location = [NSString stringWithFormat: #"%f,%f", lat, lon];
NSString* daddr = [NSString stringWithFormat: #"%f,%f", myLat, myLon];
request = [NSString stringWithFormat: #"saddr=%#&daddr=%#&zoom=%i&directionsmode=walking", location, daddr, zoom];
NSString* typeMapsApp = isGoogleMapsAppPresent ? #"comgoogle" : #"";
NSString* urlString = [NSString stringWithFormat: #"%#maps://?%#", typeMapsApp, request];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString]];
}
You're using a third party piece of code to do your route drawing, rather than using MapKit itself. The library you're using (which I found on GitHub here) hasn't been updated for two years.
I'd recommend you move away from that library to something more current. If you want you could consider using Google's iOS Map SDK, which supports iOS 6 (link here). You could combine this with Google's Directions API to draw polylines directly onto the map. Or you could stick with MKMapView, and again draw directly onto the map with polylines.
It's not that iOS has changed how it draws polylines onto a map - it's that the third-party code you're using is out of date.
I'm trying to open a Facebook link and using the following code would conform with the URL protocol on iOS.
NSString *url = [self.dataSource getFacebookURL];
url = [url stringByReplacingOccurrencesOfString:#"http://www.facebook.com/" withString:#"fb://profile/"];
NSLog(#"LINK: %#", url);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
But when trying to load a profile or a page (i.e. of an organization) it always brings me to the screen that was left open last. Is there a way of linking directly to the page and profile? I followed the instructions as described here, but no success.
The page I want to link to is "https://www.facebook.com/junction11" if that helps...
Thanks, Max
FIX
So I found a solution which is to load the group/person/page's graph values first, parse them and then make a new url with the Facebook-ID. The code works (don't know how well) and looks like this:
// Look at graph page instead of www page
NSString *dataURL = [url stringByReplacingOccurrencesOfString:#"www" withString:#"graph"];
// Load data and parse using JSON parser
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:dataURL]];
NSError *error;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if (!error) { NSLog(#"ERROR: %#", error); return; }
// If no error occurred, make new url and replace the username by the facebook-ID
url = [url stringByReplacingOccurrencesOfString:[dictionary objectForKey:#"username"] withString:[dictionary objectForKey:#"id"]];
// And voilà, it works :]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Thank you google and time...
NSURL *url = [NSURL URLWithString:#"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];
Schemes
fb://profile – Open Facebook app to the user’s profile
fb://friends – Open Facebook app to the friends list
fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)
fb://feed – Open Facebook app to the News Feed
fb://events – Open Facebook app to the Events page
fb://requests – Open Facebook app to the Requests list
fb://notes – Open Facebook app to the Notes page
fb://albums – Open Facebook app to Photo Albums list
In iOS 6 the QLPreviewController no longer loads a PDF from a URL. It works fine in iOS 5. I have implemented the QLPreviewControllerDataSource methods as documented here.
#pragma mark - QLPreviewControllerDataSource
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index;
{
NSURL *fileURL = [NSURL URLWithString:#"http://www.bliley.net/XTAL/PDF_Instructions/Test_File.pdf"];
return fileURL;
}
This works perfectly in iOS 5, however in iOS 6 the console outputs:
Couldn't issue file extension for path: /XTAL/PDF_Instructions/Test_File.pdf
Have you tried using fileURLWithPath instead of URLWithString? I had other issues that were fixed by doing so.
Also not sure if QLPreviewController will handle remote URLs. If not, you could download the file and then display it.
I downloaded the file from remote url and saved locally, then I display the PDF using the QLPreviewController .In iOS 6 its working.
First i saved the file from remote url using the following code :
NSString *local_location;
NSString *path = [[NSBundle mainBundle] pathForResource:#"sampleData" ofType:#"plist"];
path = NSTemporaryDirectory();
local_location= [path stringByAppendingPathComponent:[NSString stringWithFormat:#"My_Invoice.pdf"]];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString: remoteurl]];
[request setDownloadDestinationPath:local_location];
[request startSynchronous];
For showing the Pdf :
QLPreviewController* preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
[self presentModalViewController:preview animated:YES];
QLPreviewController delegate methods are :
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:local_location];
}
I am having a similar issue and seems like it might stem from a stricter enforcement of the file-type URL of QLPreviewItem
#property (readonly) NSURL *previewItemURL;
Discussion
This property is used by a Quick Look preview controller to get an item’s URL. In typical use, you would implement a getter method in your preview item class to provide this value.
The value of this property must be a file-type URL.
If the item is not available for preview, this property’s getter method should return nil. In this case, the Quick Look preview controller displays a “loading” view.
Availability
Available in iOS 4.0 and later.
Declared In
QLPreviewItem.h
UPDATE: I have opened a bug with Apple dealing with this issue for iOS 6 and it seems they have aced it as a bug so may offer a fix in the near future. The bug I opened had to do with using custom NSURLProtocols for the preview, but may apply to other aspects as well.
Link to class
But note that QLPreviewController expects a URL to a local resource
You would need to download and save the PDF file locally first and then create a proper file URL to the local file.
I use the following code in my iOS app to use Instagram iPhone hooks to post a photo to Instagram. I only want the "Open In..." menu to have Instagram app, no other apps. But in my case Camera+ also shows up. How can I restrict to Instagram?
Also, can I directly open Instagram instead of showing Open In menu?
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
//imageToUpload is a file path with .ig file extension
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imageToUpload]];
self.documentInteractionController.UTI = #"com.instagram.photo";
self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:#"my caption" forKey:#"InstagramCaption"];
[self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.exportBarButtonItem animated:YES];
}
BTW Instagram added an exclusive file extention (ig) and UTI (com.instagram.exclusivegram) for this. It still opens the Open with... menu but the only option is Instagram.
More info here: https://instagram.com/developer/mobile-sharing/iphone-hooks/
You can get the solution from this link.
Save image with the .igo extension instead of .ig. This is the "exclusive" version of the filetype.
Create a UIDocumentInteractionController, then assign the value com.instagram.exclusivegram to the property UTI.
Present your UIDocumentInteractionController with presentOpenInMenuFromRect:inView:animated.
This worked for me, do it like this and you will have only Instagram as the exclusive app to open your image.
NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
// *.igo is exclusive to instagram
NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:#"Image.igo"];
NSData *imageData = UIImagePNGRepresentation(filteredImage);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
_docController=[[UIDocumentInteractionController alloc]init];
_docController.delegate=self;
_docController.UTI=#"com.instagram.photo";
[_docController setURL:imageURL];
_docController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:#"#yourHashTagGoesHere",#"InstagramCaption", nil];
[_docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
To answer only your first question: you may probably be able to restrict the "Open in ..." menu to just showing Instagram for your device (by deleting the Camera+ App, for example), but you won't be able to restrict users that install your app to their devices. And that's because the iPhone recognizes which applications are able to open a specific kind of files and it automatically show every one that does.
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];
self.documentInteractionController=[UIDocumentInteractionController interactionControllerWithURL:imgurl];
self.documentInteractionController.UTI = #"com.instagram.exclusivegram";
use this code in same sequence .
here documentInteractionController is object of UIDocumentInteractionController.just for your knowledge.
you will get instagram only in "open in" window.