I'm currently trying to implement Facebook SDK into my Unity App but I can't find the AppDelegate.m that I must modify in order to implement the SDK.
I tried searching everywhere in my Xcode folder but it seems nowhere to be found.
I search on google too but as I really don't understand anything to Xcode (except from building my Unity Project), I don't understand the answers too...
Thanks, and have a nice day !
The file name “AppDelegate.m” is a generic reference to “the file that contains the definition of your application delegate class”. Your app is not required to name the file “AppDelegate.m” however, so you’ll need to find yours.
Somewhere in your app there is a class that implements the UIApplicationDelegate protocol. You should search for “UIApplicationDelegate” using Xcode’s search function. That should put you on the right track to finding the class. Whichever file that class is in is the file you need to refer to when other documentation says AppDelegate.m
Update:
I forgot that in objective-c you don't declare adoption of a protocol. Here is a different way to find your app delegate.
Find your main.m file (this file is required, so you'll definitely have one). It will contain code like this:
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([YourAppDelegateClassName class]));
}
}
The interesting piece is [YourAppDelegateClassName class], since this represents the class of your application delegate. Do a search for the first word in the square brackets, in this case it is YourAppDelegateClassName.
You can find it by searching UIApplicationDelegate in xcode search, then you will find the implemenation of this protocol in some file named as something.h.that's the file which you needed.
In Xcode 13.3.1 the file would be the (AppName)App file. This file defines the entry point for the app. This file is where you would define the app delegate class.
Related
I am trying to understand the best ways in which to bring native library code into a NativeScript plugin for iOS. I've had success in past bringing in a CocoaPod and accessing the symbols from that. So I want to create my own.
I follow the process for pod lib create TestPod to generate my library project. (https://guides.cocoapods.org/making/using-pod-lib-create.html)
The 'library' is a trivial test: it simply creates a class with a function that returns
a recognizable greeting string.
The associated "Example app" demo produces a text label that displays this string.
This all works as expected, all running in pure iOS world (written in Swift).
At the Nativescript side, I'm using the Nativescript Plugin Seed and I'm declaring my Podfile in the src/platforms/iOS folder as directed. My "plugin" (trivial as it is as a test), has the iOS-specific parts in the pluginName.ios.js file. I have a separate test method in here that verifies I can reach and use native iOS platform symbols (e.g. NSMutableString) and that works as expected. I want to do the same thing with native code imported from my library.
But when I bring the Podfile into Nativescript, it builds okay, but I'm not able to see any of the symbols as I would expect to see.
I generate typings and I don't find them either, but I do find a "TestPod.d.ts" typings file that declares some version info and a mysterious class named "UITest" that I did not define and bears no resemblance to my "SimpleTest" class, which I can't find anywhere.
I'm sure I'm missing something here that is probably obvious to the knowledgeable. But I'm unable to guess what it is. Any ideas?
import Foundation
#objc public class SimpleTest : NSObject {
public func announce() -> String {
return "Greetings from Swift code in a library"
}
}
I'm calling it in the plugin using the following:
public testNativeLib() : string {
let str:string;
try {
const testClass = new SimpleTest()
str = testClass.announce()
} catch(e) {
str = e.message;
}
return str;
}
and what I get returned for str is the catch case error message: "Can't find variable: SimpleTest"
Without seeing the source to the pod file; the only guess would be that you didn't use the #objc on anything that you wanted exposed. Without you exposing anything with #objc (or descending from a native objc class, so it is tagged by swift automagically) NativeScript cannot see it.
Please note their are some types in Swift that currently cannot be consumed by NativeScript (Or ObjC) and you have to write some wrapper code in swift around it using types that are compatible with ObjC so that NativeScript can use it.
Please see: https://docs.nativescript.org/guides/ios-source-code for more info on requirements...
The code needs to be:
import Foundation
public class SimpleTest : NSObject {
#objc public func announce() -> String {
return "Greetings from Swift code in a library"
}
}
Move the #objc to the actual property/function you want exposed. The NSObject will already cause the class to be exposed if it has exposed members.
The metadata generated:
A complete demo using a swift source file in a plugin is now located at
https://github.com/NathanaelA/demo-swift-plugin
If I have full control over the source, then I won't normally add another moving piece (i.e. cocoapod) to the mix; just let xcode compile the swift code and expose it, no need to add any additional places something can break.
However, if you want to see how to do an actual swift CocoaPod plugin; checkout any of these plugin repos that use swift code and cocoapod:
https://github.com/tomvardasca/nativescript-crypto
https://github.com/arpit2438735/nativescript-tglib
https://github.com/Daltron/NotificationBanner
In the case of an actual cocoapod; you need to have a valid Podfile, and a valid podspec file! Once you have those; when you build the application, you can open up xcode and verify that the cocoapod is linked in. If it isn't linked in then your podfile/podspec is messed up and has to do with a issue with Cocoapod and it is not a NativeScript issue. So in that case; you need to follow some Cocoapod tutorials to get it to work.
Please note; nuking your platform folder frequently while you are testing with cocoapods is highly recommended. Occasionally Nativescript does not detect the changes to Native code properly and so it then doesn't rebuild the xcode project/workspace files. So nuking your platforms folder will of course force it to rebuild them. If you don't you WILL waste a lot of time while messing around with cocoapods.
When running the sample project you will see this:
In addition, in the demo, the metadata generated from the code I saved in the demo/metadata folder so you can look at it.
Hello I'm new to programming in Objective-C. I'm reading the book "Programing in Objective-C Developers Library" and they're asking me to create a command line project using the foundation framework, but when I go to create one, I don't see an option to use Foundation.
Your first screen shot shows it:
You've already selected Command Line Tool, which is correct. So now click Next and you will be creating a command line tool that uses the Foundation framework. In your second screen shot, enter a name for the tool and click Next; you will then be asked for a place to Save this project. Do so. When you do, the code for main.m will say:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
// insert code here...
NSLog(#"Hello, World!");
}
return 0;
}
See that first line? That is "using the Foundation framework".
One thing to know is that Foundation is so important in Objective-C that it's practically part of the language. It provides classes like NSNumber, NSString, NSArray, NSDictionary, and many others that we assume are always available. So Foundation is special in that every Objective-C project will use it, and it'll be included in any project templates like the Command Line Tool template you're working from. Other project templates will include additional frameworks (e.g. the Cocoa App template will set up your project with AppKit for you), and if you want to use other frameworks you'll add them yourself after you create the project.
recently I have learned how to use the appleDoc to do the documentation for my iphone project.
But what I realize is that AppleDoc only scan the head file of each class and based on the special comment format it creates the docSet and html.
My question is that how to let the AppleDoc looking after the .m file as well. Because for classes like viewController, quite a few logic are in the .m sectors and not be exposed in the head file. (I am asking this is because in Xcode5 if you hover over a private method and press "option" button xcode does show you a hover which contain the special comment you made. That's how I guess that there must be a way to transfer these description/comment into the docSet).
Anybody has some idea please help to give me some answer.
Thanks
Finally I found out there was a line in the script command which you need to remove.
It will include all the "*.m" files where all the "private" interface comments are kept.
I'm working on a 3rd party UIKit replacement for iOS. I have it building as a framework using a seriously helpful project from GitHub. (Not mine, but if you have interest, it's here.
I'm trying to use my library in other projects I'm writing. Like I said, it's basically a drop-in replacement for much of UIKit, so I decided to import the framework in my project's *.pch file instead of everywhere I might wish to use a button, action sheet, alert view, etc...
When I DON'T have an #import directive in a header file and declare a property of type MBMButton, the compiler gives me an error of "Unknown type name 'MBMButton'; did you mean 'UIButton'?" Oddly enough, the code will still run (even though this is an error, not a warning). Adding #class MBMButton or #import <MBMUIKit/MBMUIKit.h> resolves this compiler complaint.
When I DON'T have an #import directive in an implementation file (or its header) and call a method that exists in MBMUIButton but NOT in UIButton, I get a compiler error of "No visible #interface for 'UIButton' declares the selector...". As before, the code will actually run, since it's a valid call.
Now, I've done some digging, and I've changed my project's settings. Where I didn't have any value in the GCC_PREFIX_HEADER, I added the file name. Noting the Quick Help description by Apple, I tried both "ProjectName-Prefix.pch" and "./ProjectName-Prefix.pch". Neither seemed to resolve the problem. I eventually figured out that the Target-level settings override the Project-level settings, and that the Target-level settings already specified "ProjectName/ProjectName-Prefix.pch". So that was a dead end. (Nice to learn exactly what the relative path settings are, though!)
I'm OK with not using the *.pch file. It's only a convenience, and I can definitely use appropriate #class and #import directives. What's bugging me is not understanding the issue. How should one use the *.pch file?
The prefix header file is automatically included in every .m file in your project but not in any .h files.
Therefore, any references to classes will require the header to be included or a forward declaration:
#class MyClass;
However for #protocols you'll need the full header, a forward declaration won't work:
#protocol MyProtocol; //this won't work
#interface MyController : UIViewController <MyProtocol>
…
#end
This problem is almost certainly gonna have a really simple answer, but I just can't see it. I'm programming an app for the iPhone in Xcode and I'm trying to create an instance of an ABPerson object, but can't. In my .h file, I am importing as follows:
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABPerson.h>
Then when I try to create it using "ABPerson *person;", it gives the error, "Unknown type name 'ABPerson'".
I have searched the internet and there doesn't seem to be much on the use of ABPerson and where I have seen it used, they have done it like this and its worked fine.
Ultimately, I want to create a VCard containing the details of somebody which the user can then save to their phone so if you know of another way of doing this which would eliminate this problem, that would also be great.
Thanks,
Matthew
Have you added the AddressBook framework to your app? Look in XCode4, look at your project file -> Build Phases -> Link Binary with Libraries.
Try this.
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABAddressBook.h>