iOS JPG File Association using Swift 2 - jpeg

I have an iOS Project I'm working on using Xcode7 and Swift2. I have file association working great on it with PDF files. I did this in my Info.plist. I want to now associate it with images, particularly with JPG images. I have looked online and cannot find anything for this. Can someone please help?
For PDF I have:
Which looks like this in Source Code:
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>PDFIcon64.png</string>
<string>PDFIcon320.png</string>
</array>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
</dict>
I tried copying the above and adjusting for JPG with no luck:
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>JPGIcon64.JPG</string>
<string>JPGIcon320.JPG</string>
</array>
<key>CFBundleTypeName</key>
<string>JPEG</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.xyz.JPG</string>
</array>
</dict>
I also tried this instead with no luck:
<dict>
<key>CFBundleTypeName</key>
<string>public.JPG</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>public.JPG</string>
</array>
</dict>
When I'm viewing an image in my iOS Photo Library and click on the action button, it does not list my app in the area where the Message, Facebook, Twitter, etc. apps are located, like it does with PDF files from my Mail app. I've looked online in all kinds of forums with no luck for this.

For images that will be stores with the app you should consider using an Asset Catalog.
There is one asset catalog that defaults to every project and you can store images in there.
Once you add as asset to the catalog you can reference it in a string by the name you have it (without its extension).
For example
UIImage(named: "JPGIcon64")
Here is the link to the apple doc that talks about it here

Related

Access macOS Photo Library using Electron

I am trying to write an Electron application that lets users select photos from their photo library on macOS. My assumption is that the only way to access the photos without exporting them is by going into ~/Pictures/Photos Library.photoslibrary. However, when passing the file path of a photo to an <img> tag, I get net::ERR_ACCESS_DENIED error.
Is there a way to grant Electron application access to the user's photo library?
I've been writing code recently that accesses the PhotosLibrary. I did this by writing a native module that calls the PhotoKit API. If you go that direction there's going to be a steep learning curve as you'll likely be using Objective-C++ with the features and quirks of both C++ and Objective-C while trying to write something in JavaScript.
https://github.com/nodejs/node-addon-api
https://developer.apple.com/documentation/photokit?language=objc
With Apple's recent security features, you'll also need to somehow run your code inside of an app with the correct entitlements and values set in its Info.plist that will allow access to APIs.
In build/entitlements.mac.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- https://github.com/electron/electron-notarize#prerequisites -->
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<!-- https://github.com/electron-userland/electron-builder/issues/3940 -->
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<!-- Allow app to access Photos Library using PhotoKit API -->
<key>com.apple.security.personal-information.photos-library</key>
<true/>
</dict>
</plist>
The following will be needed in your App's Info.plist:
<plist version="1.0">
<dict>
...
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to the photos library</string>
</dict>
</plist>
This can be done using electron-builder by adding the following value to the extendInfo extendInfo of your mac build settings in package.json.
{
...
"build": {
...
"mac": {
...
"extendInfo": {
...
"NSPhotoLibraryUsageDescription": "This app needs access to the photos library"
}
}
}
}
I hope this is gives you something to start with. Like I said above, this will come with a steep learning curve unless you're already familiar with JavaScript, native module development, Objective-C, C++ and Apple's APIs.
If you just need to read data from it for a one-off project, the photolibrary is really just a directory-like container around your photos, and an sqlite database for the metadata (faces, places and albums/folders). Right click-the photolibrary, show package contents, orig photos are under Masters/YYYY/MM/DD/IMG_XXXX.JPG format, and metadata is in database/photos.db, some tables you can query are RKMaster (filename/uuid of master files), RKAlbum, RKFace, RKMemory, RKPlace, RKFolder, RKVersion, RKKeyword, etc., get any free sqlite browser and you can figure out the rest.
You can also copy the .photolibrary file to Linux and scan its folder/sqlite file using pure node, you don't need any native modules to read it. Writing to it may try to fire some sqlite triggers that seem to belong to some macosx-proprietary extensions, so make backups first, try writes with extensions disabled, or just read and extract the images and metadata to some other format (raw jpeg/json files in a bucket somewhere) that are easy to collate and then (if you have to), reverse the process and write out to another photolibrary file once you get the relation between the tables and filesystem paths inside its container.

Deep-linking Xamarin iOS

I need to add deep linking feature to my app with Xamarin iOS.
My info.plist looks like this:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>domine.somthing/index.html?UV</string>
</array>
<key>CFBundleURLTypes</key>
<string>com.domine.somthing/index.html?UV</string>
</dict>
I seems not working due to "/" char in the URL.
How am I supposed to write CFBundleURLTypes and CFBundleURLSchemes URL values in order to make it work?
Deep links can returns users directly to your application.
After adding URI support to your application like you did, just clicking on a URL consisting of a scheme name for your application will launch your app, but it seems you are filling CFBundleURLSchemes and CFBundleURLTypeswith with wrong values.
CFBundleURLName - Usually, this corresponds to the bundle ID of your
application. Please see Apple's Development doc for more informations.
CFBundleURLSchemes - Array of strings containing URL scheme names,
usually at least your application's name (without spaces). Pay
attentiont to ensure these values are unique to your application.
Look at this sample:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.yourcompany.yourapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>appname</string>
</array>
</dict>
</array>
Now clicking on a URL consisting of appname:// on the device will launch your app.
If you want to send a user to a specific part of your application, you need to add arguments to this URL, making a deep link. Here is a sample with a path and query:
appname://custompath?customquery=customvalue
When a user clicks a URL containing your scheme (appname://), your app's delegate is called and specifically the method OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)where you can handle schemas an execute correct app routing based on schema arguments (if provided).

Google earth sequential placemarks on a time delay

I have a KML file with a few different placemarks all around the globe. I would like to flyto the first placemark and display it's balloon, wait a minute or two, then flyto the next placemark, and repeat this process until all of the placemarks have been shown.
I think I might be able to achieve this by putting all the placemarks into a tour but this doesn't seem like the right approach. I'm going to be refreshing the KML from a server and I'm not sure how a tour would react to that (e.g., I think you have to always click play before starting a tour).
If this isn't possible I may have to place just a single placemark in the KML file and then keep refreshing the file with a different placemark. I think that approach might be bad though because it will be refreshing a lot more.
I ended up putting one placemark per KML file. I wrote a program in Java that uses the Saxon processor and an XSLT stylesheet to create multiple KML files with just a single placemark per file then using this tutorial I was able to cycle through the KML files one-by-one.
When doing this locally on my machine I created two folders. Folder A housed all the KML files. Folder B would house only one KML file which would be the file expected from the KML NetworkLink tag. In the Java program I had a timer thread that sequentially deletes the single file in Folder B, cuts a file out of Folder A, moves it into Folder B, then renames the newly placed file the common name which the KML NetworkLink tag expects. I hope this helps and the link will help this to make more sense.
(Base KML file which is loaded into Google Earth - Basically tells Google Earth to look for the file called every10.kml every 10 seconds. If we swap that file out, say, every 9 seconds, then once it's refreshed by Google Earth it will be a new KML file thus showing the new placemark)
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<NetworkLink>
<Link>
<href>every10.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>10</refreshInterval>
</Link>
</NetworkLink>
</Document>
</kml>

Xcode: Compare two NSMutableArrays

I have two NSMutableArrays(initialized from plist file contents) that contains Dictionary objects. Could anyone please help me with the best method to achieve following result. The structure of Array is:
I want to compare two following arrays to get the old entries which is not exists in new array.
Old Array:
<dict>
<key>ResourceId</key>
<string>352</string>
</dict>
<dict>
<key>ResourceId</key>
<string>3115</string>
</dict>
New Array:
<dict>
<key>ResourceId</key>
<string>352</string>
</dict>
<dict>
<key>ResourceId</key>
<string>4629</string>
</dict>
I want the resulted array contains following entry:
<dict>
<key>ResourceId</key>
<string>3115</string>
</dict>
Thanks.
Converting NSMutableArray to NSMutableSet objects and then using Intersect method should be the best one..

How to display a moving boat in Google Earth?

I am new to the KML format and try to figure out how to display a boat (a png), moving from a place to another along a path (a simple line drawn composed of several lines).
I can see how to display a Placemark, even with an icon, and a Path, separately.
What I would like to see when I click on the KML file is :
the boat appearing at the departure point;
the path drawing itself until the arrival;
the boat icon moving at a comfortable speed (bonus point it I can set a ration time / progress, extra bonus if I can click on start, pause or rewind) from departure to arrival along the path.
Is that even possible ? I know it is with Google Map, but you can program it with Javascript, which eases things a lot.
This is an old question, and there is now a better way to move a placemark (or even better a model) along a pre-determined linestring. Look into using this feature:
http://code.google.com/apis/kml/documentation/kmlreference.html#gxtrack
Sample code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
<Folder>
<Placemark>
<gx:Track>
<when>2010-05-28T02:02:09Z</when>
<when>2010-05-28T02:02:35Z</when>
<when>2010-05-28T02:02:44Z</when>
<when>2010-05-28T02:02:53Z</when>
<when>2010-05-28T02:02:54Z</when>
<when>2010-05-28T02:02:55Z</when>
<when>2010-05-28T02:02:56Z</when>
<gx:coord>-122.207881 37.371915 156.000000</gx:coord>
<gx:coord>-122.205712 37.373288 152.000000</gx:coord>
<gx:coord>-122.204678 37.373939 147.000000</gx:coord>
<gx:coord>-122.203572 37.374630 142.199997</gx:coord>
<gx:coord>-122.203451 37.374706 141.800003</gx:coord>
<gx:coord>-122.203329 37.374780 141.199997</gx:coord>
<gx:coord>-122.203207 37.374857 140.199997</gx:coord>
</gx:Track>
</Placemark>
</Folder>
</kml>
The only way I've been able to make this work in static KML is to interpolate between the start and stop points and add placemarks for each frame I want to animate. So, from t=0 to t=1, draw a placemark at the start point. From t=1 to t=2, draw a placemark at the next point, etc.
This gives you the temporal player bar in Google Earth and you can rewind or advance the animation. However it is a little annoying because you wind up with every interpolation point in your placemark tree. Putting the placemarks in their own folder keeps them out of the way, but there's no way to hide them from the user.
Take a look at http://code.google.com/apis/kml/documentation/time.html#animating
The whale shark example does more or less what you want for the placemark. (The URL for the marker icon is broken). Animating the progress along the track can be done using the same trick.
If you want to try something much more difficult, you can try serving dynamic KML. Have Google Earth load a network link to your initial data. Then load another network link with an that sends an update for your placemark at every time tick.
http://code.google.com/apis/kml/documentation/kmlreference.html#link
http://code.google.com/apis/kml/documentation/updates.html
This approach has some serious disadvantages because it requires an external program to drive Google Earth and it does not give the user access to the built-in Google Earth temporal player bar. It also requires that all the data be loaded over a network link -- KML data from a file cannot be updated. That means your driver program needs to act as a http server. Also, in this model it is very hard to know exactly when Google Earth has finished loading and drawing the update. Really I don't recommend doing this; you can make it work using the Google Earth COM API, but it will always be a fragile solution.
There's a browser plug-in that lets you embed Google Earth into a browser page. From there you can use JavaScript to animate your placemark, change your paths, etc. Check out the Google Earth API Developer's Guide.
If you are going to display a boat on Google Earth, a 3D model would be a better approach then an image, since the users can change the viewing angle.
You might want to look into tours: http://code.google.com/apis/kml/documentation/touring.html
I've seen something like this done using a combination of (a number of) <gx:AnimatedUpdate> tags to move a previously created placemark representing your boat and <gx:FlyTo> tags to move the view (I think) all within a <gx:Playlist>.
Hope this helps.
I'm presuming this functionality did not exist when originally answered, but you can achieve the effect using a tour. The following shows a placemark moving in this fashion.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document>
<Placemark id="boat">
<Point>
<coordinates>0,0</coordinates>
</Point>
</Placemark>
<gx:Tour>
<name>Play me!</name>
<gx:Playlist>
<gx:FlyTo>
<gx:duration>5.0</gx:duration>
<LookAt>
<longitude>0</longitude>
<latitude>0</latitude>
<altitude>0</altitude>
<heading>-95</heading>
<tilt>65</tilt>
<range>250000</range>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
</gx:FlyTo>
<gx:AnimatedUpdate>
<gx:duration>5.0</gx:duration>
<Update>
<targetHref/>
<Change>
<Placemark targetId="boat">
<Point>
<coordinates>1,1</coordinates>
</Point>
</Placemark>
</Change>
</Update>
</gx:AnimatedUpdate>
<gx:Wait>
<gx:duration>6.0</gx:duration>
</gx:Wait>
</gx:Playlist>
</gx:Tour>
</Document>
</kml>
The path could be marked with points whose visibility is altered by the tour at the appropriate time.
I have following sample in Google site. Hope this help.
(details inside : https://sites.google.com/site/canadadennischen888/home/kml/auto-refresh-3d-tracking)
prepare a RestFul service to generate KML file from DB
(sample as in https://sites.google.com/site/canadadennischen888/home/kml/3d-tracking)
My other code will generate a KMZ file which has a link to my Restful service
(sample as in this page)
KMZ file has onInterval
Web page allow user to download KMZ file which has URL that link to my Restful service
When Google Earth open KMZ file, Google Earth will auto refresh to get new data from that Restful service
Just google for "kml time animation"
KML: Time and Animation
KML: Animation
Animation and Dynamic Updates with KML

Resources