I'm trying to embed an youtube video in swiftUI app (building for iOS 14)
i'm using CocoaPods with the following Podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '14.0'
target 'TestProjectYoutube' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for TestProjectYoutube
pod 'Alamofire', '~> 5.0'
pod 'SwiftyJSON', '~> 4.0'
pod 'URLImage'
pod 'Introspect'
end
I've created the following view
import SwiftUI
import CoreData
struct ContentView: View {
#Environment(\.managedObjectContext) private var viewContext
var body: some View {
VStack() {
VideoView(videoID: "CX-BdDHW0Ho")
}
}
}
struct VideoView: UIViewRepresentable {
let videoID: String
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView(frame: CGRect(x: 0.0, y: 0.0, width: 0.1, height: 0.1))
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
guard let youtubeURL = URL(string: "https://www.youtube.com/embed/\(videoID)") else { return }
uiView.scrollView.isScrollEnabled = false
uiView.load(URLRequest(url: youtubeURL))
}
}
The error i got is:
2023-01-16 15:35:16.130698+0100 app[44720:3273388] -[__NSArrayM length]: unrecognized selector sent to instance 0x2824115c0
2023-01-16 15:35:16.130920+0100 app[44720:3273388] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x2824115c0'
*** First throw call stack:
(0x18048bc80 0x197cb1ee4 0x18055c708 0x18042556c 0x18042477c 0x18ac78644 0x18e74ce50 0x18e9d0ca4 0x18e9d0888 0x18e94c418 0x18e963de0 0x18ecdd224 0x18ecdcec8 0x18e72b69c 0x18e727c4c 0x18e72cd18 0x18ac73590 0x18ac7410c 0x1804ac468 0x1804bc598 0x1803fe774 0x180403e48 0x180417194 0x1a0f56988 0x182c1aa88 0x1829b3fc8 0x187c6cd68 0x187bb783c 0x187b9d1dc 0x10281f3fc 0x10281f530 0x102ff84d0)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x2824115c0'
terminating with uncaught exception of type NSException
When I replace the youtube.com with google.com, i dont get the error and google is loaded.
Can someone help me with this?
Related
I am just presenting GMSAutocompleteViewController but it is crashing even though i have made separate application. Crash only happen on release mode but not on debug mode. But ealier ios 15 everything was working. I have added the api key in appdelegate and it is working on debug mode and below is the code:
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
autocompleteController.modalPresentationStyle = .overFullScreen
present(autocompleteController, animated: true, completion: nil)
Application Specific Information:
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
CoreSimulator 802.6.1 - Device: iPhone 13 Pro Max (13ED85A0-1287-44A4-B21F-CD56D7109BCC) - Runtime: iOS 15.5 (19F70) - DeviceType: iPhone 13 Pro Max
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <NSConcreteMapTable: 0x7f780792d7d0> was mutated while being enumerated.'
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot**
var datePickerView: UIDatePicker = UIDatePicker()
override func viewDidLoad() {
super.viewDidLoad()
initializeBarButtons() }
func initializeBarButtons() {
datePickerView.datePickerMode = UIDatePickerMode.date // This is the line that gets the error
datePickerView.addTarget(self, action: #selector(EmployeeDetailEditViewController.handleDatePicker), for: UIControlEvents.valueChanged)
}
This commented line is causing the crash when the calendar is changed from Gregorian to Buddhist.
Crash : -
Terminating app due to uncaught exception 'NSRangeException', reason:
'* -[__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond
bounds [0 .. 1]'
* First throw call stack: (0x18626e364 0x1854b4528 0x186206e9c 0x186136840 0x18f9a1890 0x1902238a8 0x19022045c 0x1902210f4
0x19022139c 0x190214254 0x1902136cc 0x190213c08 0x190213d24
0x1013881e0 0x101386d1c 0x101387018 0x18f768590 0x18f768304
0x18f8d2bd4 0x18f7f5c4c 0x18f7f5890 0x18f7f5790 0x1a53e4c18
0x18f74cf00 0x18a2b1998 0x18a2b5b20 0x18a22236c 0x18a249b90
0x18a24a9d0 0x186215edc 0x186213894 0x186213e50 0x186133e58
0x187fe0f84 0x18f7b367c 0x10131b378 0x185c5056c) libc++abi.dylib:
terminating with uncaught exception of type NSException
How to Solve This ?
Unfortunately, you can't solve it, as there is an open radar on it (https://openradar.appspot.com/41120005).
Meanwhile, use #Amey workaround:
if #available(iOS 11.0, *) {
let gregorianCalendar = Calendar(identifier: .gregorian)
self.datePickerView.calendar = gregorianCalendar
} else {
// Fallback on earlier versions
}
I'm receiving a run-time error on the following statement inside of my ViewController class. This seems so straightforward, but tons of searching and videos later, I can't figure out what I did wrong.
class ViewController: UIViewController {
// Main image view controller
#IBOutlet var drawing_ImageView: UIImageView!
// store a point coordinate value based on screen touch
var start = CGPoint(x: 0, y:0)
}
The var start = CGPoint(x: 0, y:0) line throws the error. I also tried:
var start: CGPoint
but that also throws an error. What am I missing? No build or compile errors are thrown.
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
My app crashes and throws this error
[UITouchesEvent rightView]: unrecognized selector sent to instance 0x13d5092e0
2016-08-04 17:07:15.569 [3809:1375151]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITouchesEvent rightView]: unrecognized selector sent to instance 0x13d5092e0'
*** First throw call stack:
(0x180d72db0 0x1803d7f80 0x180d79c4c 0x180d76bec 0x180c74c5c 0x1000e681c 0x1000e6a60 0x185f08be8 0x185f08b64 0x185ef0870 0x185f11360 0x185f07ed8 0x185f00c20 0x185ed104c 0x185ecf628 0x180d2909c 0x180d28b30 0x180d26830 0x180c50c50 0x182538088 0x185f3a088 0x1000f5c88 0x1807ee8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm trying to make a custom class for hide and show password so that I can use it in any UITextField in any UIViewController.
class HideShowIcon:NSObject {
var showPasswordImage = UIImage(named: "ic_show_password") as UIImage?
var hidePasswordImage = UIImage(named: "ic_hide_password") as UIImage?
func hideShowPasswordButton(hideText:UITextField) {
var hideShowSize: CGSize = "12345".sizeWithAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14.0)])
var hideShow: UIButton = UIButton(type: UIButtonType.System)
hideShow.frame = CGRect(x: 0, y: 0, width: hideShowSize.width, height: hideText.frame.size.height)
hideShow.setImage(hidePasswordImage, forState: UIControlState.Normal)
hideText.rightView = hideShow
hideText.rightViewMode = UITextFieldViewMode.Always
hideShow.addTarget(self, action: #selector(HideShowIcon.hideShowPasswordTextField(_:hideText:)), forControlEvents: UIControlEvents.AllTouchEvents)
}
func hideShowPasswordTextField(sender: AnyObject,hideText:UITextField) {
var hideShow: UIButton = (hideText.rightView as? UIButton)!
if !hideText.secureTextEntry {
hideText.secureTextEntry = true
hideShow.setImage(hidePasswordImage, forState: UIControlState.Normal)
} else {
hideText.secureTextEntry = false
hideShow.setImage(showPasswordImage, forState: UIControlState.Normal)
}
hideText.becomeFirstResponder()
}
}
You can not use selector with many parameters hideShowPasswordTextField(_:hideText:) for UIButton target. You can only use selector with one (or zero) parameter, in which UIButton will put itself: hideShowPasswordTextField(_:)
func hideShowPasswordTextField(sender: UIButton) {
//...
}
To use hideText in this function, you may declare it as property of your class:
var hideText: UITextField!
and assign value to it in class initialization step
I'm using the following library:
https://github.com/lukabernardi/LBBlurredImage
This is the code I'm using to blur my background image that I'm adding to a ViewController:
var background = UIImage(named: "bg")
var backgroundImageView = UIImageView(image: background)
backgroundImageView.contentMode = .ScaleAspectFill;
backgroundImageView.setImageToBlur(background, blurRadius: 10, completionBlock: { () -> Void in
println("The blurred image has been set")
})
self.view.addSubview(backgroundImageView)
I'm getting the following error and I'm not sure why:
-[UIImageView setImageToBlur:blurRadius:completionBlock:]: unrecognized selector sent to instance 0x7ff08a802390
2015-01-27 10:50:44.326 TestApp[9289:66346] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setImageToBlur:blurRadius:completionBlock:]: unrecognized selector sent to instance 0x7ff08a802390'
UPDATE:
Looks like I'm not the only one to receive the error.
Exception was that the image I was passing was nil and in turn it was violating NSParameterAssert(image);
var background = UIImage(named: "bg")
Instead of this try to specify the full path of the image.
It worked for me and I am pretty sure it will work for you too.
You can also try this path with your code
var background = UIImage(named: "Images/bg");