how to register the app to open the pdf file in my app in ipad - objective-c

i want to open the pdf file in my app from pdf page,
but i am not getting any option of opening the pdf in my app.
this my info.plist file
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeIconFiles</key>
<string>Icon.png</string>
<key>LSItemContentTypes</key>
<string>com.neosofttech.pdf</string>
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.pdf</string>
</array>
<key>UTTypeDescription</key>
<string>PDFReader File</string>
<key>UTTypeIdentifier</key>
<string>com.neosofttech.pdf</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>pdf</string>
</dict>
</dict>
pls tell me where i am wrong in this, how can i open the pdf file in my app.

I'm assuming that you're trying to open an attachment from within Mail based on your plist here. Since you don't own the PDF file type you can't declare it as an exported type. You only need to declare it as a supported document type.
For example:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
</dict>
</array>
You can find a list of all of the system supplied content types here or in UTCoreTypes.h.
When someone does open a PDF file and chooses your application that file will be copied to an Inbox subdirectory of your Documents folder in your app sandbox. Your app will then be opened and within your app delegate's application:didFinishLaunchingWithOptions: your launchOptions dictionary will contain a UIApplicationLaunchOptionsURLKey key specifying the URL of the file within your sandbox that you can then work with.

You can't do what you're trying to do unless you do the following:
Register a custom url with the system
Call that custom url from within a hyperlink inside the PDF
Generate a PDF with clickable links
So what this means is that you register a custom url handler in your info.plist. For example, let's say you create a custom url handler with the form coolapp://. Now, inside of your document from which you generate the PDF, when you create a hyperlink, have it use your custom URL, for example coolapp://filedetails?pdfurl=mywebsite.com/path/to/pdffile.pdf&pageno=5. You then have to parse this in -application:handleOpenURL:. Download the file specified in the pdfurl field and then jump to the page specified in pageno.
Keep in mind that this assumes you are creating the PDF in question yourself. If you do not control the PDF content creation process, you cannot do what you are wanting to do. There is no way to open your app from an arbitrary PDF. It has to be done using a custom URL.
Let me know if you need clarification.

Insert code below to info.plist
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>"*"</string>
</array>
<key>CFBundleTypeName</key>
<string>Unknown</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
</dict>
</array>

Old post - but I landed on here also looking for a way to pass a PDF to my App.
The plist depicted by Ashley Clark help me to register my App as an App that can take a PDF file as a parameter. +1 for him on that one :-)
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
</dict>
</array>
However, to fully implement this, I used the following method in my AppDelegate.m file:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
NSLog(#"sourceApplication: %#", sourceApplication);
NSLog(#"url: %#", url);
The above runs when the App is opened as I was running Safari and had a PDF that I wanted to share from there.
Above, I can determine which App passed my App the PDF and the URL to it's location.
When run, it outputs the following:
sourceApplication: com.apple.mobilesafari
url: file:///Users/me/Library/Developer/CoreSimulator/Devices/C395439F-7A0D-434F-8D78-D4615DB643E1/data/Containers/Data/Application/E3B181BC-6075-4F2C-923D-2ECC642DA555/Documents/Inbox/pdf-5.pdf
I can then use the URL to open the PDF and do whatever I want with it in my App.

Related

What is the way to update info.plist with the URL Scheme when using branch.io?

I am reading conflicting information so unsure what to do.
According to this document: https://help.branch.io/developers-hub/docs/ios-basic-integration#2-configure-associated-domains
I need to submit a URL Scheme. Recommendations? Apple says reverse DNS.
According to this document: https://branch.io/glossary/uri-schemes/
URL Schemes are obsolete.
What should I do?
A Branchster here -
While most of the redirection happens through Universal Links on iOS there can be certain situations where a third-party app is not able to trigger UL and in that case, the fallback redirection using URI schemes comes into the picture.
Ideally, you should set up both Universal Links and URI schemes in your Info.plist file so that you cover all the edge cases. You can check out the recommendations for the URI scheme here though just ensure it is something unique to your app.
To start you need to configure your Branch Dashboard enabling Universal Links toggle and entering your URI scheme and app information -
You can then proceed to enter the same information in your project's Info.plist file -
<key>branch_universal_link_domains</key>
<array>
<string>sample.app.link</string>
<string>sample-alternate.app.link</string>
<string>sample.test.app.link</string>
<string>sample-alternate.test.app.link</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.your.schene</string>
</array>
<key>CFBundleURLName</key>
<string>com.branch.monster</string>
</dict>
</array>
<key>branch_key</key>
<dict>
<key>live</key>
<string>key_live_</string>
<key>test</key>
<string>key_test_</string>
</dict>

Possible unhandled promise rejection (id: 0)

I've been having this problem for over a month now, this error occurs whenever I try to login to my react-native app using a mobile device.
This is the error
And this is the code to login in my react native app
There's this part of the docs you need to take note of. What you are missing is adding an App Transport Security exception, since you are not using localhost as server, and https is required.
By default, iOS will block any request that's not encrypted using SSL.
If you need to fetch from a cleartext URL (one that begins with http)
you will first need to add an App Transport Security exception. If you
know ahead of time what domains you will need access to, it is more
secure to add exceptions only for those domains; if the domains are
not known until runtime you can disable ATS completely. Note however
that from January 2017, Apple's App Store review will require
reasonable justification for disabling ATS. See Apple's documentation
for more information.
An example of ATS is as follows, in info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>example.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
For android, similarly from docs
On Android, as of API Level 28, clear text traffic is also blocked by
default. This behaviour can be overridden by setting
android:usesCleartextTraffic in the app manifest file.
You can refer to https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic
If you are using some api that is hosted on some server. It must have https because in latest devices http request is forbidden.

Safari extension background script by default not allowed to access sites in SFSafariWebsiteAccess in Info.plist

I'm developing a Safari extension and need the background script to be able to use the browser.webRequest.onBeforeRequest API when certain pages are loaded (let's say, example.com pages).
I have this in my manifest.json:
...
"permissions":["*://*.example.com/*"]
...
And I have this in the Info.plist for the extension target in my macOS app:
...
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.web-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string>
<key>SFSafariWebsiteAccess</key>
<dict>
<key>Level</key>
<string>Some</string>
<key>Allowed Domains</key>
<array>
<string>example.com</string>
</array>
</dict>
</dict>
...
The extension is working except that the extension does not by default have access to example.com pages. When I build the extension in Xcode and load it in Safari, then go to Safari > Preferences > Extensions > My Extension > Edit Websites, example.com is listed under "Configured Websites", but with the Ask option selected. If I update it to Allow, the extension works as expected.
How can I configure the app such that the extension automatically has access to example.com pages when the user activates it? I've seen other extensions that have access to webpages automatically, but I don't know how they do it.
Many, many thanks for your help!
Documents reviewed:
https://developer.apple.com/documentation/safariservices/safari_app_extensions/safari_app_extension_info_property_list_keys/adjusting_website_access_permissions
https://developer.apple.com/documentation/safariservices/safari_web_extensions/managing_safari_web_extension_permissions
It appears that that's the default and can't be changed. Safari simply handles the hosts in permissions as suggested websites rather than pre-approved websites. The user has to manually enable each website in the options or via the "browser action" button.

Download from sites that require a login using ffmpeg

I want to download HLS videos from a site that needs to be logged in using FFmpeg, meaning I have to enter my username and password to access the videos, and I do not know how to enter the login information through FFmpeg...
Can anyone help me?
First login to site using puppeteer or any other automation tool and grab all related cookies.
then use command like that
ffplay -cookies "nlqptid=nltid=tsn; path=/; domain=somedomain.com;" http://somedomain.com/somestream.m3u8
for more details view this url
HLS is an adaptive streaming protocol, which means that the video streaming can be automatically adjusted for better video playback experience by dividing the video file into multiple smaller chunks with different data rates. Because now you have many small chunks you cannot directly download the video. In fact, you cannot even find the direct download link to the video file.
But if you closely look at the network requests using your developer tools in your browser, you can get the manifest file with .M3U8 extension. This is the file which contains the url to all the smaller chunks of the video.
If the video is not drm protected, which in most cases will be drm protected, you can use ffmpeg as shown below:
ffmpeg -i "http://xyz.domain.com/video_url.m3u8" -c copy -bsf:a aac_adtstoasc "output.mp4"
But based on your explanation, it looks like there is some kind of authentication mechanism to this website to watch the content, which means most probably the video will be drm protected.
In this situation you will need to find the keyID and the key from the developer tools in browser by manually going through the manifest file. This can be done programtically by creating a manifest parser methid which will return all the video segments. audio segments, video keyIds, and audio keyIds.
Then store the keyIds and keys in a dict for later retrieval.
So now you have the keyID and key, then you can decrypt each segment using the key as shown below using ffmpeg:
ffmpeg -y -decryption_key {key} -i {segment_filename} -codec copy -metadata title={video_title} dec_{filename}
Most probably you will need to do this separately for the video and audio and then decrypt and then mux them back together to get the original file with audio and video.
Please not this is not an easy task, but will require a bit of manual investigation into the specific service providers requests and responses.
Please also note that the solution/idea proposed is strictly for research purposes and should not be used for any illegal activities.
As per our knowledge, it's not possible because I am unable to get any method on FFmpeg from where we can set the password.
Trick:
you can create a password protucted page and where implemnet video downloads logic like this:
download.php
<?php
/* Your password */
$password = 'MYPASSWORD';
if (isset($_POST['password']) && $_POST['password'] == $password) {
// Download video logic here....
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Password protected</title>
</head>
<body>
<div style="text-align:center;margin-top:50px;">
You must enter the password to view this content.
<form method="POST">
<input type="text" name="password">
</form>
</div>
</body>
</html>

OSX/Cocoa : setting up service in menu for right click and services list

I have followed all the Apple documentation for setting up a service for a right click menu list and for the services list:
I have made all the relevant info.plist entries. (send types, port name, menu title, instance method, etc.)
I have created the method which handles services.
I have added service registration code in the app.
I built my app, put it in the application directory, logged out and back in.
Despite all this I cannot see my service in any menu item.
EDIT**
Here is the services part of my info.plist:
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>MyApp/Send to MyApp</string>
</dict>
<key>NSMessage</key>
<string>contentService</string>
<key>NSPortName</key>
<string>MyApp</string>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
<string>NSFileContentsPboardType</string>
</array>
</dict>
</array>
What am I doing wrong? thanks in advance.
I have followed all the Apple documentation for setting up a serviceā€¦
Ah, that's the problem: You stopped there. You also need to add the NSRequiredContext key to your service to get it to be enabled by default on Snow Leopard and later.
Fortunately, while the Services documentation doesn't mention that NSRequiredContext is required, the Information Property List Key Reference does explain the value you must provide for it.