Calling an obsolete class on xcode - objective-c

how to call a class that's not in xcode's interface builder?
I am calling QTMovieView on xcode 6 and xcode 6 doesn't have it in the interface builder
my mac app requires that it should install and play movies on 10.6 and later
here's what i've done
I added an object to the View Controller and name it as QTMovieView
and I've connected the property movieView to the QTMovieView.
IS this correct

You will need to compile against the 10.5 SDK.

Related

How to identify actual touchBar hardware is available in an Mac book using obj c?

How to identify actual touchBar hardware is available in an Mac book using obj c code so that i can provide touchbar menu options.
From the Apple documentation :
There is no need, and no API, for your app to know whether or not there is a Touch Bar available. Whether your app is running on a machine that supports the Touch Bar or not, your app’s onscreen user interface (UI) appears and behaves the same way.
To check if touch bar is available (to improve UI/UX for example) you should implement the delegate and set a Bool like :
// Declare a class variable
#property (nonatomic, assign) BOOL isTouchBarAvailable;
#available(OSX 10.12.1, *)
// A bellow version can not be installed on a new MacBook.
// Like an iPhone 7 can't have iOS9 installed.
- (NSTouchBar *)makeTouchBar
{
// ... here the code to make the bar
self.isTouchBarAvailable = YES
return touchBar
}
Source : https://developer.apple.com/reference/appkit/nstouchbar?language=objc
NSTouchBar can work in software as well as hardware, as show by the simulator in Xcode. It doesn't require the hardware to work. However, the Xcode 8 release notes tells you how to test if the OS can support any kind of Touch Bar functions.
https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html
Xcode 8.1 supports Touch Bar for Macs that include it, and supports adding Touch Bar functionality to your app. (28859277)
Before using Touch Bar functionality in your app, confirm that the app is running on a macOS version that includes support for Touch Bar using a runtime check.
For example, the following Objective-C code performs a runtime check to make sure NSTouchBar is available:
NSClassFromString(#"NSTouchBar") != nil
In Swift code, do an availability check for macOS 10.12.1, and a runtime check for Touch Bar class availability. For example:
NSClassFromString("NSTouchBar") != nil
If you want some control you can use isAutomaticCustomizeTouchBarMenuItemEnabled:
import Cocoa
#NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Here we just opt-in for allowing our instance of the
// NSTouchBar class to be customized throughout the app.
if #available(OSX 10.12.2, *) {
NSApplication.shared().isAutomaticCustomizeTouchBarMenuItemEnabled = true
}
}
/*
Whether or not a menu item to customize the touch bar can be automatically
added to the main menu. It will only actually be added when hardware
or simulator is present. Defaults to NO. Setting this property to YES
is the recommended way to add the customization menu item.
*/

iOS how can I use storyboard elements that don't exist in earlier versions of iOS?

I have a project originally targeting iOS7 using a storyboard. I've added a UIStackView to a view controller and get an error that "UIStackView before iOS 9.0". The build fails because of this error.
How can I keep my project as iOS7, while conditionally including newer storyboard elements from iOS9 if device supports them?
I already have conditional code in the project that only runs on iOS8+, but how can I do something similar with a storyboard?
The class UIStackView (and its software) is provided by iOS 9, but is not provided by iOS 8 or 7. When the app tries to instantiate an object from the storyboard in iOS 8, it will fail because it cannot find the class.
The only ways around this:
have different storyboards for different iOS vesions
build a custom class that does the same thing. Then you can use it in the older versions of the iOS. You might find open source libraries that already do this for the class you want.

Xcode 5 document template Apps OS X: Where to do the Apps lifecycle

I am new to programming for Mac (not iOS but OS X) and so have run into a problem. The template providing a document based application doesn't come with an appDelegate class. Only class provided and used is the NSDocument subclass.
My Problem: Where do I put the - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender (or equivalent) method I need in order to call a NSAlert? If I place it into my NSDocument subclass, it never gets called.
Thanks for any help.
Solved it! Just had to implement my own AppDelegate class (however I didn't know how to do this. I just looked in a test app (non document base) how it goes).
Also, I looked here: X-Code Interface Builder Not showing App Delegate Object

Application Delegate - Cocoa

I want to incorporate an applicationDidFinishLaunching: into my cocoa delegate. How would I do this?? On the iphone SDK the applicationDidFinishLaunching is already in the application delegate, but when making my mac application I noticed that there were none.
Best Regards,
Kevin
As of Xcode 3.2, the Mac application template also comes with an application delegate, already connected, that has such a method.
To set this up in a project created before Xcode 3.2, create a new class for your delegate to be an instance of. I usually name mine “AppDelegate”. You'll do this by right-clicking on the Classes group and choosing “Add File”, then picking the Cocoa NSObject Subclass file template.
Open the header you just created (AppDelegate.h). Give it any instance variables you want. Then hit Go to Counterpart. That takes you to the implementation file (AppDelegate.m). Add your applicationDidFinishLaunching: instance method here. Unlike on the iPhone, this is a notification-handler method, so it takes an NSNotification instance and not an NSApplication instance.
Now to hook it up. In the Resources group, open MainMenu.nib. Drag an Object from the Library window into the top-level nib window (the one with icons in it, such as File's Owner and First Responder). Select the object you just created and open the Identity inspector. Set the object's class to AppDelegate, matching the name you used in Xcode. Right-click on the File's Owner, and drag from its delegate outlet to your new object.
In Xcode, add an NSLog statement to your applicationDidFinishLaunching: method. Hit Save All, then Build and Go. Switch back to Xcode and open the Debugger Console. If you did everything right and I didn't forget anything, you should see the log message there.
- (id)init
{
if (self = super init]) {
[NSApp setDelegate:self];
}
return self;
}
You can also do this in Interface Builder; from "File's Owner" in MainMenu.xib, just drag the "delegate" outlet to your object. You may want to consider using -awakeFromNib instead though.
Were you missing the application delegate files altogether? It seems as though there's a bug in the Xcode installation scripts (at least for 3.2.1 on Snow Leopard) that installs the latest project templates in the wrong folder. The older template for a "Cocoa Application" project doesn't contain the delegate files.
I've explained what I've discovered (and how I "fixed" it) in a blog post called Fixing the Xcode Project Templates.
Cheers,
Graham

AppDelegate file missing in Xcode 3.1?

i am currently starting to learn Xcode and objective-c and i am reading three different books on that topic currently. All of these books refer to a file called "AppDelegate" (My_First_ProjectAppDelegate.m, My_First_ProjectAppDelegate.h) which are said to be "created with the Project" (i am creating a "Cocoa Application"). These files are not present when I create a new Project. I seem to be not the only one having this problem (see http://pragprog.com/titles/dscpq/errata ).
Is there any more information about AppDelegate? What is the current practice on how to deal with a missing Appdelegate? i am using Xcode Version 3.1.4 on Mac OSX Leopard.
AppDelegate is nothing more than a common NSObject class with needed connections in MainMenu.xib. You can easily recreate your own:
Create a class, name it AppDelegate
Open MainMenu.xib and add NSObject object to object palette
In object inspector's Identity tab (the last one) set object's class to AppDelegate (you should get autocomplete)
Ctrl+drag from Application object to your newly created AppDelegate object and choose "delegate" from opened panel.
As I recall, only the iPhone templates were providing delegate classes by default. This is not a huge deal, but I can see how you would be concerned if you are just learning. Are you sure what you are reading is relevant to MacOS applications and not Iphone?
You can always create your own delegate class manually. You just create a class as you normally do, then set it as the delegate for NSApplication in Interface Builder.
I think the confusion comes from the version of XCode you are using.
Xcode version 3.2 changed the default behavior when you create a new project: it now creates an AppDelegate for your project. I can't remember what the earlier versions did, but it was different.
As Eimantas says, if you want to use an AppDelegate then you can just create one following the steps he describes.