Is there any way to get the file name from PHAsset object in iOS 8, same as like ALAsset's defaultRepresentation provides the file name?
// For ALAsset
let defaultRepresentation = self.asset.defaultRepresentation()
let filename = defaultRepresentation.filename()
NOTE: This can be done in iOS9 using PHAssetResource class. But I am looking for iOS8 and documented way of doing this(No undocumented APIs Please).
I did find the same question on SO but did not find the convincing answers, so I thought of asking it separately.
Any pointers would be greatly appreciated.
There have a private API called PHAsset.filename.
let filename = phAsset.value(forKey: "filename") as! String
You will get something like "IMG_193.PNG".
There is no documented way to do this on iOS 8.
The only thing you "might" use is the PHImageFileURLKey returned in the info Dictionary of the method requestImageDataForAsset: of PHImageManager. But even this is not fully documented.
Related
Based on this WWDC2018 video, we can dynamically change how words are pronounced in AVSpeechSynthesizer.
I'm trying to do that in my Xamarin App, but I can't find the accessibilitySpeechIPANotation constant.
In the doc of NSMutableAttributedString.AddAttribute(...) it says that the constants can be found here: UIKit.UIStringAttributeKey. Yet the one I'm looking for isn't there.
Does anyone know what the actual string value of the constant is? Or even better, where I can find in in Xamarin.iOS?
(My app uses xamarin.ios v4.0.30319, if the constant is in a newer version of the framework, I'll update it, but google doesn't seem to give me any result when I search for it.)
Cause:
Xamarin for iOS is based on Objective-C.And there are some differences between swift and Objective-C.
Solution:
The code is just like the following :
var attriStrng = new NSMutableAttributedString(new NSString("hello iPhone"));
// you can set the voice here ,a͡͡a͡͡a͡͡a͡͡a͡͡ is just for testing
attriStrng.AddAttribute(new NSString("AVSpeechSynthesisIPANotationAttribute"), new NSString("ˈa͡͡a͡͡a͡͡a͡͡a͡͡a͡͡a͡͡.ˈfo͡ʊn"),new NSRange(6,6));
var voice = new AVSpeechUtterance(attriStrng);
AVSpeechSynthesizer synthesizer = new AVSpeechSynthesizer();
synthesizer.SpeakUtterance(voice);
I have an NSUrl object and want to read the file name. While searching for existing solutions on StackOverflow I found https://stackoverflow.com/a/19964302/25282 which is for iOS but it uses syntax like return [yourURL lastPathComponent]; where it is unclear to me how to translate it into the C# that I have to use in Xamarin.iOS.
the equivalent C# for this Obj-C code
return [yourURL lastPathComponent];
is
return yourURL.LastPathComponent;
where yourURL is a NSUrl;
I have found a few questions regarding this issue, yet none of them were helping with my problem. I am trying to save an object to core data using this code (which worked perfectly fine in Xcode 6 and Simulator...):
let fetchRequest = NSFetchRequest(entityName: "Patient")
let fetchedResults : [NSManagedObject]!
do {
fetchedResults = try managedContext.executeFetchRequest(fetchRequest) as! [NSManagedObject]
patienten = fetchedResults
} catch {
print("error")
}
I added the do-try-catch once I started working on this project in the Xcode 7 beta and a physical device.
Now, when I hit the Save button, this piece of code is called, the app freezes and I get the following:
warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.
Does anybody know where I went wrong?
For anyone coming across this in the future, I just ran into this problem myself and it turned out that I was actually getting a stack overflow from a recursive function.
Apparently calling setValue:forKey: on an NSObject calls the respective set[Key] function, where [Key] is the (capitalized) name you gave to the forKey section.
So, if like me, you have code that looks like the following, it will cause an infinite loop and crash.
func setName(name: String) {
self.setValue(name, forKey: "name")
}
Choose Product > Clean
I had similar issue. I deleted the app from the device. Then "Product->Clean" in the XCode menu. When I ran the app again, the issue got resolved.
Swift 3:
Actually this problem happened often when you have any property in input declared as type NSError and the compiler expect an Error output, so change the input type to Error usually solve this issue.
What helped me in similar problem (xCode 7, Swift 2):
reading this question
Or more quickly without explaining the reason of solution: just comment #objc(className) in your NSManagedObjectSubclass , that was generated from your CoreData Entity (#objc(Patient) - in your case ).
This solution (if issue still appears) does not applicable to xCode 7.1/Swift 2.1, as the way of generating NSManagedObjectSubclasses was changed.
Don't forget about cleaning your project (Product > Clean) and deleting the app from your device/simulator to replace CoreData storage on it.
let fetchRequest = NSFetchRequest(entityName: "Patient")
do {
let fetchedResults = try managedObjectContext!.executeFetchRequest(fetchRequest)
print("\(fetchedResults)")
} catch {
print("error")
}
The above code worked for me.
Maybe the issue maybe with how your core data is managed.
Check if your managedObjectContext is actually getting created.
Check the modelling of your core data
I followed the steps described in this tutorial.
I tried to translate the code from Objective-C to Swift. This is the code I have:
var l2tpInterface = SCNetworkInterfaceCreateWithInterface(
kSCNetworkInterfaceIPv4,
kSCNetworkInterfaceTypeL2TP
).takeUnretainedValue();
var pppInterface = SCNetworkInterfaceCreateWithInterface(
l2tpInterface,
kSCNetworkInterfaceTypePPP
).takeUnretainedValue();
var prefs = SCPreferencesCreate(nil,"SoybeanVPN",nil).takeUnretainedValue();
var service = SCNetworkServiceCreate(prefs, pppInterface).takeUnretainedValue();
var success = SCNetworkServiceEstablishDefaultConfiguration(service);
This code returns a runtime error EXEC_BAD_ACCESS(code=1) at the first line.
I googled this error and someone said the problem is caused by using released object in Objective-C? Is that the same in Swift? Does anyone have any experience with VPN creation in Swift?
UPDATE:
I tried to debug and find the const value of kSCNetworkInterfaceIPv4 is invalid, see the attached image:
Is that a bug of Swift?
I believe kSCNetworkInterfaceIPv4 is not the problem, because I can use it just fine to create L2TP/IPSec and Cisco VPNs using Swift.
It's rather tricky to handle C pointers in Swift, but this is how I do it, using Swift 2.3. Notice the wrapping/unwrapping with ! of C-Reference objects.
let initialTopInterface: SCNetworkInterfaceRef!
let initialBottomInterface: SCNetworkInterfaceRef!
// L2TP on top of IPv4
initialBottomInterface = SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4, kSCNetworkInterfaceTypeL2TP)
// PPP on top of L2TP
initialTopInterface = SCNetworkInterfaceCreateWithInterface(initialBottomInterface!, kSCNetworkInterfaceTypePPP)
let service = SCNetworkServiceCreate(usingPreferencesRef, initialTopInterface!)
// Now you assign the attributes
SCNetworkServiceSetName(service, ("Some Name" as CFString))
// myConfiguration is a Hash with your relevant Key/Value pairs
SCNetworkInterfaceSetConfiguration(topInterface!, myConfiguration)
// Here is a good example for why Swift may just crash if you're not careful
let temporaryString:CFString = "IPSec"
SCNetworkInterfaceSetExtendedConfiguration(topInterface!, temporaryString, myL2tpConfiguration)
SCNetworkServiceEstablishDefaultConfiguration(service)
You can find a working implementation (for macOS Sierra) on Github
Just need copy all SCNetworkInterface's
SCNetworkInterfaceCopyAll()
Insert it at the beginning, before creating interfaces
I am investigating Windows 8 Store app development, and am having trouble locating the following members
Type.IsClass
System.ComponentModel.DesignerProperties.IsInDesignTool
Visual studio claims they don't exist, but MSDN suggests they should.
I am obviously missing something silly: Can anyone point me in the right direction please?
Regards
John.
The IsClass property has moved to the TypeInfo class. Basically you need to replace;
bool result = type.IsClass;
with;
bool result = type.GetTypeInfo().IsClass;
GetTypeInfo() is an extension method from the System.Reflection namespace, no not obviously visible on System.Type unless you're already using System.Reflection.
The IsInDesignTool property has moved to another place too and changed name;
bool result = Windows.ApplicationModel.DesignMode.DesignModeEnabled;