Open UIImagePickerController in landscape - ios

I am trying to present UIImagePickerController in landscape mode for iPhone, as my application supports only landscape mode.Which works fine with iOS 11.But whenever I run my application in iOS 10.3.3 it gets crash the same time with error :
*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES' * First throw call stack:**

Create an extension of UIImagePickerController like below
extension UIImagePickerController
{
override open var shouldAutorotate: Bool {
return true
}
override open var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return .all
}
}
Hope that will help you

Related

How to turn on/off Portrait Orientation Lock iPhone in Swift

I've used my code to set the screen's brightness.
UIScreen.main.brightness = CGFloat(0.5)
Can I use the code to enable and disable the screen orientation lock of my iPhone?
Thanks for all the help!
• Set the shouldAutorotate to False
override open var shouldAutorotate: Bool {
return false
}
• Specify the orientation.
override open var supportedInterfaceOrientations:UIInterfaceOrientationMask {
return .portrait
}
P.S : You can do this for in a screen in your app, not on the system (iPhone).
You can use this to update device orientation:
UIDevice.current.setValue(UIDeviceOrientation.portrait.rawValue, forKey: "orientation")
Or
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
3rd party applications can't manipulate all system settings or other app settings as it is likely going to cause security breaches. It's called sandboxing. Every app has it's own "Sandbox" or to put it simply, a prison where it cannot access/manipulate system settings or other app settings, which make the Apple devices really secure.
Although you can manipulate the orientation of you application using
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}

Orientation does not rotate in iOS 10 but does rotate in iOS 11

I don't have a physical device with iOS 10 to test this on but in any device running iOS 10 in the simulator, the app doesn't rotate, it stays in portrait. However, in iOS 11, it rotates fine. All of the orientation boxes are checked in the Info.plist and whether I use or omit (which is the only bit of code in the entire app that deals with orientations):
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.allButUpsideDown
}
in any view controller (root or otherwise), it has no affect in iOS 10. The app is entirely constraint based and there are navigation controllers, which I've read can cause issues. But everything that has been suggested in those answers didn't work for me. Something is preventing the app from rotating in iOS 10 and I cannot figure it out.
This method also returns nothing in iOS 10 (but works in iOS 11):
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
if size.width > size.height {
print("orientation: \(UIDevice.current.orientation)")
} else {
print("orientation: \(UIDevice.current.orientation)")
}
}
I've disabled everything in the app and still nothing in iOS 10.
This is issue which is seen only in iPhone 6 plus simulator. It works fine when we run in device or other simulators iPhone 6, iPhone 7, SE. And also this issue is not seen in iPhone 6 plus device .

App crashes when trying to resign keyboard

Since I updated to the latest Xcode 6 beta, I have been having issues with closing the keyboard. My app is crashing each time I try to close the keyboard, even though I have used the same code for ages and it used to work fine.
Here is what I have:
#IBAction func viewTapped(sender : AnyObject) {
//Closes keyboard when user touches screen.
transactionDateInput.resignFirstResponder()
transactionNameInput.resignFirstResponder()
textField.resignFirstResponder()
notesField.resignFirstResponder()
UIView.animateWithDuration(1.5, animations: {
self.valueEnter.alpha = 0
self.dateEnter.alpha = 0
self.notesDone.alpha = 0
})
}
Someone suggested changing it to something like this:
if (transactionDateInput.isFirstResponder() == true){
transactionDateInput.resignFirstResponder()
}
but that makes no difference. Anyone have any suggestions? Here is the error:
AffordIt[4445:1334424] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AffordIt.SecondViewController textFieldShouldReturn:]: unrecognized selector sent to instance 0x7fb169666880'
Check your Text Field outlet delegate (right click to Text Field)
there should be delegate to your UIViewController!
Look at this tutorial

Does openParentApplication:reply require App Groups capability to be enabled?

I am developing an app that communicates between the watch and the iOS parent app. It sends data from the WatchKit extension to the parent application by opening it. I understand that openParentApplication:reply, when called, opens the iPhone application from the Apple Watch. After that, application:handleWatchKitExtension:reply is called in the app's delegate.
From there you can open a notification to the view controller with:
NSNotificationCenter.defaultCenter().postNotificationName(aName: String, object anObject: AnyObject?)
"aName" is what you can open up in the view conroller with:
NSNotificationCenter.defaultCenter().addObserver(self,
selector: Selector("handleWatchKitNotification:"),
name: "WatchKitSaysHello",
object: nil)
Here is my code for my interface controller in my WatchKit extension:
//
// InterfaceController.swift
// SendColors WatchKit Extension
//
// Created by Tommy on 12/30/14.
// Copyright (c) 2014 Tommy. All rights reserved.
//
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
var ypo = false
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// Configure interface objects here.
}
#IBOutlet weak var redButton: WKInterfaceButton!
#IBOutlet weak var greenButton: WKInterfaceButton!
#IBOutlet weak var blueButton: WKInterfaceButton!
#IBAction func onRedButtonClick() {
if ypo {
openParentAppWithColor("Yellow")
}
else {
openParentAppWithColor("Red")
}
}
#IBOutlet weak var moreButton: WKInterfaceButton!
#IBAction func moreButtonClick() {
if !ypo {
ypo = true
redButton.setTitle("Yellow")
redButton.setColor(UIColor.yellowColor())
greenButton.setTitle("Purple")
greenButton.setColor(UIColor.purpleColor())
blueButton.setTitle("Orange")
blueButton.setColor(UIColor.orangeColor())
moreButton.setTitle("Back")
}
else {
ypo = false
redButton.setTitle("Red")
redButton.setColor(UIColor.redColor())
greenButton.setTitle("Green")
greenButton.setColor(UIColor.greenColor())
blueButton.setTitle("Blue")
blueButton.setColor(UIColor.blueColor())
moreButton.setTitle("More...")
}
}
#IBAction func onGreenButtonClick() {
if ypo {
openParentAppWithColor("Purple")
}
else {
openParentAppWithColor("Green")
}
}
#IBAction func onBlueButtonClick() {
if ypo {
openParentAppWithColor("Orange")
}
else {
openParentAppWithColor("Blue")
}
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
private func openParentAppWithColor(color: String) {
if ["color": color] != nil {
if !WKInterfaceController.openParentApplication(["color": color], reply: { (reply, error) -> Void in
println(reply)
}) {
println("ERROR")
}
}
}
}
My problem is that say for instance I clicked the red button on the watch simulator. The action would be called and in that action it calls openParentApplicationWithColor("Red") which would call WKInterfaceController.openParentApplication(["color": color], reply: { (reply, error) -> Void in }) What this is supposed to do is open the parent app on the simulator. It opens it in the background. I, therefore open it manually. When I open the app manually, the background is completely black. I suspect the problem is that I did not enable App Groups in the Capabilities tab. In order to do that, you need to be in the developer program. Should I join it to do this, or is there another problem? I am using Xcode 6.2 Beta 3. Thank you all in advance!
I have tested and can confirm that openParentApplication:reply: does not require App Groups to be enabled.
I understand that openParentApplication:reply, when called, opens the iPhone application from the Apple Watch.
This method opens the iPhone app in the background. In previous betas of Xcode 6.2 the app did open in the foreground, but this was not the intended behaviour and is not how the WatchKit Extension-iPhone app communication will work in the shipping version.
You can still launch the iPhone app in the foreground manually, but this isn't necessary unless you want to test the use case of both being used at once. At least with the API currently available, the iPhone app it can't be launched programmatically by the watch app to the foreground, and the watch app can't be launched programmatically by the iPhone app.
Once the app launches, you've reported the screen is still black when you expect it to change colour based on the message you've sent it. Is application:handleWatchKitExtension:reply: being called in the iPhone app? You will know it is definitely being called if you are receiving the reply block back for execution in your WatchKit Extension, which should be outputting something from your println(reply). If so, then the issue is with the code in the iPhone app to do something with the message you've passed to it. It would be useful to see your implementation of that method in your AppDelegate of the iPhone app. (Note if that method failed to call the reply block, it might still be receiving the message and you wouldn't get the reply, but then you would be seeing an error message about the reply not being received.)
Note that you won't see NSLog messages or get breakpoints in Xcode when running the Watch extension initially, but you can select Debug > Attach to process > [select your iPhone app under 'Likely targets'] and then you will get the logs and breakpoints of the iPhone app instead of the Watch app, while still being able to use the Watch app in the watch simulator. Most useful for debugging.
No, you no need to make group enable to use ole parent application. you can make a request to open parent IOS application and waiting a reply from IOS App without setting the group app. You only need to setting the group app when you want to share data between watchkit app and IOS app using NSUserDefauts with suite name.
I am using Xcode 6.2 Beta 5. Select Debug > Attach to process > [select your iPhone app under likely targets is not working. I see the NSLogs for Watch extension but not in iPhone app delegate and view controller of iPhone app.

Unusual NSInternalInconsistencyException related to device orientation

I am getting an unusual error on an iPad app I am working on:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Card''
*** First throw call stack:
(0x35ef988f 0x31872259 0x37aee7e5 0x8aadd 0x30a35e33 0x30a42391 0x30a42201 0x30a420e7 0x30a41969 0x30a416ab 0x30a4156b 0x30a000bd 0x35e581fb 0x37349aa5 0x373496bd 0x373495c9 0x30b7ea73 0x30ae0b1f 0x30b7212b 0x30b720bb 0x30a40ba9 0x30bb8927 0x34c6e2e9 0x34c6de23 0x30bbeae9 0x34c47f09 0x35e587d3 0x35e59461 0x30c741af 0x30c7594d 0x30bab509 0x30a34893 0x30a2e8d7 0x309fcc6b 0x309fc70f 0x309fc0e3 0x35bcf22b 0x35ecd523 0x35ecd4c5 0x35ecc313 0x35e4f4a5 0x35e4f36d 0x30a2da13 0x30a2ae7d 0x83631 0x835f0)
This occurs only when I change my view controllers shouldAutorotateToInterfaceOrientation from:
return YES;
to:
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
Why would this cause an NSInternalInconsistencyException?
I did notice when debugging, that shouldAutorotateToInterfaceOrientation gets called about 20 times by the same function: [UIViewController _isSupportedInterfaceOrientation:]. This is not done recursively.
My app only has Landscape (left) and Landscape (right) in the supported orientations and Landscape (left) as the intial orientation
Thanks in advance.

Resources