I want to open specific file in iBooks App. I'm using UIDocumentsIntractionController to send this file to iBooks App. My code:
class ViewController : UIViewController {
...
...
#IBOutlet var iBooksBtn: UIButton!
#IBAction func book(sender: AnyObject) {
let ibookPath = NSBundle.mainBundle().pathForResource("test1",ofType: "ibooks")!
interactionController = UIDocumentInteractionController(URL: NSURL(fileURLWithPath:ibookPath))
interactionController.UTI = "com.apple.ibooks"
interactionController.presentOpenInMenuFromRect(CGRectZero,inView:self.iBooksBtn, animated:false)
}
...
...
}
So, for now i store this file in mainBundle, but in future i want to download it from the Internet. So when i press button, i got few results to
choose:
But i want to open this file ONLY with iBooks and without requests to choose App (as on picture). As far as i know i need to use UTI for *.ibooks file, i guess UTI, that i used is wrong. Thanks for any help. Also custom URL scheme (ibooks:// and etc.) is not working for me.
To open iBooks you should use custom URL scheme:
To open the library:
NSString *stringURL = #"ibooks://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
To open the iBooks store at a particular book page, you have to add the complete URL to that particular book:
NSString *stringURL = #"itms-books://itunes.apple.com/de/book/marchen/id436945766";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = #"itms-bookss://itunes.apple.com/de/book/marchen/id436945766";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Related
I have a iBook file (say SampleiBook.iba) within the app bundle (not in documents directory).
Now i just want to open SampleiBook from within app. I tried this,
NSString *path = [[NSBundle mainBundle] pathForResource:#"SampleiBook" ofType:#".iba"];
NSString *stringURL = [#"ibooks://" stringByAppendingPathComponent:path];
NSURL *url = [NSURL URLWithString:stringURL];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
NSLog(#"Yes");
}
[[UIApplication sharedApplication] openURL:url];
the iBook application gets opened, showing only the files within the iBook application. But i want the one in app bundle to be opened.
Please guide me in achieving this.
It appears that you are trying to load the .iba (iBooks Author Book) file from your app. This not going to work because .iba is the file that contains your source for the .ibooks file type that I think you really want to load.
I am writing in swift these days. Here is a swift example I just ran. Assumes that the unbutton is wired from a nib or storyboard
#IBOutlet weak var iBooksBtn: UIButton!
#IBAction func iBooksBtnPressed(sender: AnyObject)
{
let ibookPath = NSBundle.mainBundle().pathForResource("Cupertino",
ofType: "ibooks")!
let url = NSURL(fileURLWithPath: ibookPath)
let interactionController = UIDocumentInteractionController(URL:url!)
interactionController.presentOptionsMenuFromRect(CGRectZero,
inView:self.iBooksBtn, animated:false)
}
You will have to use the UIDocumentInteractionController to open the iBook in iBooks.
You can easily create an instance for the iBook in mian bundle:
NSURL *iBookResourceURL = [[NSBundle mainBundle] URLForResource:#"SampleiBook" withExtension:#"iba"];
UIDocumentInteractionController *interactionController =
[UIDocumentInteractionController interactionControllerWithURL: iBookResourceURL];
i have a button on a view controller and i want to click the button and it goes to a web site.
the website is held on parse.com.
the code as follows
- (IBAction)WebAddressBtn:(id)sender {
NSString *url = [self.exam objectForKey:#"Website"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
NSLog(#"website: %#",url);
}
the NSLog shows Null for the value url
but the data is held at
self.exam objectForKey:#"Website"
NSLog confirms its there
this works and will go to google
- (IBAction)WebAddressBtn:(id)sender {
NSString *url = #"http://www.google.com";
//[self.exam objectForKey:#"Website"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
NSLog(#"website: %#",url);
}
if i try
NSURL *url = [self.exam objectForKey:#"Website"];
url is still showing as Null
but i know the data is in self.exam objectForKey:#"Website
NSLog Output for data
name = "DMK Media & Photography Ltd";
phone1 = 01993835148;
phone2 = 07795966848;
postcode = "OX28 4BT";
products = "<PFRelation: 0x10dc75320>(<00000000 00000000>.(null) -> products)";
website = "http://www.dmkmedia.co.uk";
[UIApplication sharedApplication] openURL wont work properly if it doesnot have properly formatted url. Please check whether your url has "http://"
I am trying to download and open .ics file in my app.
I found few question, and here's some code I am using
// NSString *path = [[NSBundle mainBundle] pathForResource:#"http://www.nmsd.wednet.edu//site/handlers/icalfeed.ashx?MIID=607" ofType:#"ics"];
NSURL *url = [NSURL fileURLWithPath:#"http://www.nmsd.wednet.edu//site/handlers/icalfeed.ashx?MIID=607"];
UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:url];
dc.delegate = self;
[dc presentPreviewAnimated:YES];
Nothing at all happens. no errors at all. Would it be easier to look for a library to achieve this.
If you have a link to remote .ics file, then prepare it for Safari.
Let's suppose that you have a link to iCal file:
"pl-dev2.office.org/events/sync.ics?t=90613b6c7f8".
Just add prefix webcal:// to your link.
Swift
let link = "webcal://pl-dev2.office/events/sync.ics?t=90613b6c7f8"
let webcal = NSURL(string: link)
UIApplication.sharedApplication().openURL(webcal)
Objective-C
NSString *link = "webcal://pl-dev2.office/events/sync.ics?t=90613b6c7f8"
NSUrl *webcal = [NSURL URLWithString:link];
[[UIApplication sharedApplication] openURL:webcal];
Safari will sync it in your Calendar app for You.
The #Bartłomiej Semańczyk is adding a calendar, if you want to add a event you can open url with SFSafariController
let link = "https://www.apple.com/v/apple-events/home/p/built/assets/event.ics?d=3213214324313"
let url = URL(string: link)!
let safariVC = SFSafariViewController(url: url)
present(safariVC, animated: true, completion: nil)
You use NSURL fileURLWithPath with an URL string as parameter although it expects file path. Change it to NSURL URLWithString.
I'm trying to open an iBook via my iPhone app using this code :
- (void)goToiBookStore {
NSURL *url = [NSURL URLWithString:#"itms-books://itunes.apple.com/us/book/le-secret-du-poids/id711921224"];
//NSURL *url = [NSURL URLWithString:#"itms-bookss://itunes.apple.com/us/book/le-secret-du-poids/id711921224"]; // Also tried
//NSURL *url = [NSURL URLWithString:#"https://itunes.apple.com/us/book/le-secret-du-poids/id711921224?l=fr&ls=1"]; // Also tried
// On teste si iBook installed
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
else {
[[[UIAlertView alloc] initWithTitle:#"iBooks" message:NSLocalizedString(#"installer ibooks lab", nil) delegate:self cancelButtonTitle:NSLocalizedString(#"annuler", nil) otherButtonTitles:NSLocalizedString(#"installer", nil), nil] show];
}
}
But, the URL does not send me to the iBook in iBooks but to the download page, is it normal ?
http://img4.hostingpics.net/thumbs/mini_953506photo.png
You can open iBooks, or open the store for that product, but not open a book directly.
If you want to open iBooks:
NSString *stringURL = #"ibooks://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
UPDATE 2019:
You can open iBooks to a specific book now by including the assetid of the book you want to open. Example:
ibooks://assetid/1396541327
Details available on the Apple.com website - https://support.apple.com/en-us/HT202929
For launching video on youtube app, I am using below code.
NSURL *instagramURL = [NSURL URLWithString:#"youtube://foo"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSLog(#"opening youtube app...");
NSString *stringURL = #"http://www.youtube.com/watch?v=H9VdapQyWfg";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
} else {
// open in UIWebView in WebViewViewController
WebViewViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:#"webinterface"];
secondView.headerLabel = #"YouTube";
secondView.webPath = #"http://www.youtube.com/watch?v=H9VdapQyWfg";
[self.navigationController pushViewController:secondView animated:YES];
}
Now client changed the mind and asking to put channel in iPhone app.
For testing, I used link http://www.youtube.com/user/richarddawkinsdotnet
BUT when I use this link, instead of youtube app, it always opens in SAFARI. :(
Any idea/ suggestion on how can I open channel in YouTube app with link provided?
You're code's going wrong because, although you're checking if you can open the youTube URL more or less correctly, you're then just opening a web address, which will always open in Safari.
This is the code I've just used, which is working for me. You might want to modify the else statement if you want to fallback to using a webviewcontroller as this will open Safari if the youtube app isn't installed.
NSString *channelName = #"TheNameOfTheChannel";
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:#"youtube://user/%#",channelName]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.youtube.com/user/%#",channelName]];
if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
// Can open the youtube app URL so launch the youTube app with this URL
[[UIApplication sharedApplication] openURL:linkToAppURL];
}
else{
// Can't open the youtube app URL so launch Safari instead
[[UIApplication sharedApplication] openURL:linkToWebURL];
}
Same answer, but shorter:
if (![[UIApplication sharedApplication] openURL: [NSURL URLWithString: #"youtube://user/%channelName%"]]) {
NSURL *webURL = [NSURL URLWithString:#"http://www.youtube.com/user/%channelName%"];
[[UIApplication sharedApplication] openURL: webURL];
}
and twitter:
if (![[UIApplication sharedApplication] openURL: [NSURL URLWithString: #"twitter://user?screen_name=%channelName%"]]) {
NSURL *webURL = [NSURL URLWithString:#"http://twitter.com/%channelName%"];
[[UIApplication sharedApplication] openURL: webURL];
}
And here is a more exhaustive list of apps:
http://wiki.akosma.com/IPhone_URL_Schemes
youtube://user/<channel-id> stopped working in iOS 9 so i research and found this working well now in iOS 9
youtube://www.youtube.com/channel/<channel-id>