What does "No visible #interface for 'App Delegate'..." mean? - ios

//
// AppDelegate.m
//
#import "AppDelegate.h"
#import "MainViewController.h"
#import "SetupViewController.h"
#import <Cordova/CDVPlugin.h>
#import "NSObject+Utils.h"
#import "WebProjectSetupHelper.h"
#import "WebProjectSetupHelperDelegate.h"
#import "LoadingView.h"
#import "AppDelegate.h"
#import "MainViewController.h"
#import "NSObject+Utils.h"
#import "DeviceModelInfo.h"
#import "UIDevice+System.h"
#import "Alert.h"
#interface AppDelegate () <WebProjectSetupHelperDelegate>
#property (nonatomic, strong) WebProjectSetupHelper *helper;
#property (nonatomic, strong) LoadingView *loadingView;
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self createItemsWithIcons];
// determine whether we've launched from a shortcut item or not
UIApplicationShortcutItem *item = [launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];
if (item) {
NSLog(#"We've launched from shortcut item: %#", item.localizedTitle);
} else {
NSLog(#"We've launched properly.");
}
return YES;
}
I am using this code in my App Delegate but on the line that contains "[self createItemsWithIcons];", I get an error that says "No visible #interface for 'AppDelegate' declares the selector 'createItemsWithIcons'".
Any idea what I am doing wrong? I am trying to add quick actions with 3D touch to my app.
Update! I got that issue resolved. Now my next question is from my AppDelegate, how can I run code that is in different file? In the "www" folder there is a file that ends in .js. In that file, there is javascript code that I want to run. Any Ideas on how to call that file?

You have missed to add implementation for createItemsWithIcons method.
https://github.com/versluis/3D-Touch/blob/master/3D%20Touch/AppDelegate.m
If you are working with 3D-Touch sample, then add this code to AppDelegate:
- (void)createItemsWithIcons {
// create some system icons (doesn't work)
// UIApplicationShortcutIcon *loveIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeLove];
// UIApplicationShortcutIcon *mailIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeMail];
// UIApplicationShortcutIcon *prohibitIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeProhibit];
// icons with my own images
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:#"iCon1"];
UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:#"iCon2"];
UIApplicationShortcutIcon *icon3 = [UIApplicationShortcutIcon iconWithTemplateImageName:#"iCon3"];
// create several (dynamic) shortcut items
UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc]initWithType:#"com.test.dynamic" localizedTitle:#"Dynamic Shortcut" localizedSubtitle:#"available after first launch" icon:icon1 userInfo:nil];
UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc]initWithType:#"com.test.deep1" localizedTitle:#"Deep Link 1" localizedSubtitle:#"Launch Nav Controller" icon:icon2 userInfo:nil];
UIMutableApplicationShortcutItem *item3 = [[UIMutableApplicationShortcutItem alloc]initWithType:#"com.test.deep2" localizedTitle:#"Deep Link 2" localizedSubtitle:#"Launch 2nd Level" icon:icon3 userInfo:nil];
// add all items to an array
NSArray *items = #[item1, item2, item3];
// add this array to the potentially existing static UIApplicationShortcutItems
NSArray *existingItems = [UIApplication sharedApplication].shortcutItems;
NSArray *updatedItems = [existingItems arrayByAddingObjectsFromArray:items];
[UIApplication sharedApplication].shortcutItems = updatedItems;
}

Related

Can't get Orientation notification on iPhone without UIViewController

I am trying to develop an iPhone app using xcode13 with iPhone 11 simulator. I used Xcode template to create a basic app. Now I created a new class (not derived from UIViewController) and tried to get orientation notifications, but I am getting nothing. I tried to add the same code on class that derived from UIViewController and it worked. why ? why ?
Why it is only working from the UIViewController's derived class?
Can I make it work from a class that isn't derived from UIViewController ?
here is my code that is not working :
main.m
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Orientation/Orientation.h"
int main(int argc, char * argv[]) {
NSString * appDelegateClassName;
#autoreleasepool {
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
NSLog(#"Hello world !");
OrientationService * os = [[OrientationService alloc] init];
[os onStart];
}
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}
Orientation/Orientation.h
#ifndef Orientation_h
#define Orientation_h
#interface OrientationService : NSObject {
NSInteger * orientation_state;
}
- (void) onStart;
- (void) orientationStateDidChange:(NSNotification*) notification;
#end
Orientation/Orientation.m
#endif /* Orientation_h */
#import <Foundation/Foundation.h>
#import "Orientation.h"
#import <UIKit/Uikit.h>
#implementation OrientationService
-(void) orientationStateDidChange:(NSNotification*) notification {
NSLog(#"got notified");
}
-(instancetype)init{
self = [super init];
NSLog(#"OrientationService alloc");
return self;
}
-(void)onStart{
NSLog(#"starting orientation service");
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationStateDidChange:) name:(UIDeviceOrientationDidChangeNotification) object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
#end
I spent so long on this but it just hit me! It's because os in main() isn't being retained in memory. Instead, either implement the functionality in the App Delegate, or retain an instance of your OrientationService object in the App Delegate. For example:
AppDelegate.h
#import <UIKit/UIKit.h>
#include "Orientation.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) OrientationService *os;
#end
AppDelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
#synthesize os;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
os = [[OrientationService alloc] init];
[os onStart];
return YES;
}
#end

Objective C - No know class method for selection

I'm trying to implement a database system where an entity contains some methods in its DataClass.m but I cannot call them in my ViewController.m
In the code above I try to call savePersona but the build says
No known class method for selector
'savePersona:etaLabel:indirizzoLabel:contextLabel:'
ViewController.m
#import "ViewController.h"
#import "Giovanni+CoreDataClass.h"
#import "AppDelegate.h"
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
/*
* Event after clicking button Save.
*/
- (IBAction)btnSave:(id)sender {
NSString *nome = _insertName.text;
NSString *eta = _insertAge.text;
NSString *indirizzo = _insertIndirizzo.text;
// Check for all inputs
if ([nome isEqualToString:#""] || [eta isEqualToString:#""] || [eta intValue] <= 0 || [indirizzo isEqualToString:#""] ) {
_resultText.text = #"All fields are required";
return;
}
[Giovanni savePersona:nome etaLabel:[eta intValue] indirizzoLabel:indirizzo contextLabel:[((AppDelegate *)[[UIApplication sharedApplication] delegate]) managedObjectContext]];
}
Giovanni+CoreDataClass.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#interface Giovanni : NSManagedObject
+(void)savePersona: (NSString*)nome etaLabel:(int16_t)eta indirizzoLabel:(NSString*)indirizzo contextLabel:(NSManagedObjectContext *)context;
#end
#import "Giovanni+CoreDataProperties.h"
Giovanni+CoreDataClass.m
#import "Giovanni+CoreDataClass.h"
#implementation Giovanni
+(void)savePersona: (NSString*)nome etaLabel:(int16_t)eta indirizzoLabel:(NSString*)indirizzo contextLabel:(NSManagedObjectContext *)context {
Giovanni *p1 = [[Giovanni alloc] initWithContext:context];
p1.nome = nome;
p1.eta = eta;
p1.indirizzo = indirizzo;
}
In Build Phases I have Giovanni+CoreDataClass.m and Giovanni+CoreDataProperties.m.
In Copy Bundle Recources I have DatabaseExample.xcdatamodeld (DatabaseExample is the name of the project)
Looks like you have named your class file as category, but you are not using categories.
Try to rename Giovanni+CoreDataClass to something like GiovanniCoreData.
I have resolved my problem by recreating the project.
Nothing has changed but it seams that XCode encounter some problems on autocreating my entities when i click on Editor -> Create NSManagedObject Subclasses...
I don't know if it's a bug of the latest versione but now the project works fine.

React Native call iOS ViewController

How to call native iOS viewController' code when in RN?
Like use RN to push to a native iOS viewController and then let the native code do the job.
You need to use Export Method .
AppDelegate.h
#import <UIKit/UIKit.h>
#import "RCTBridgeModule.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate,RCTBridgeModule>
#property (nonatomic, strong) UIWindow *window;
#end
AppDelegate.m
#implementation AppDelegate
RCT_EXPORT_MODULE()
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//NO Change Here
}
RCT_EXPORT_METHOD(pushVC:(NSString *)vcName){
Class ctrlClass = NSClassFromString(vcName);
UIViewController *newVc = [[ctrlClass alloc] initWithNibName: vcName bundle: nil];
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:newVc animated:YES completion:nil];
}
You can call above response in javascript like this:
import { NativeModules } from 'react-native'
NativeModules.AppDelegate.pushVC('viewControllerNameHere')
But I highly recommend to make with external file to bridge like documentation explain here:
https://facebook.github.io/react-native/docs/native-modules-ios

Can't get Rdio iOS SDK playback to work

I'm messing around with Rdio's iOS SDK. I've set up everything correctly in "Getting Started" outlined here (http://www.rdio.com/developers/docs/libraries/ios/). The track key in the app delegate works and plays after I launch the app.
Now I'm trying to get a simple UIButton click to play a track, and I can't for the life of me get it to work.
I have this in ViewController.h
#import <UIKit/UIKit.h>
#import <Rdio/Rdio.h>
#interface ViewController : UIViewController <RdioDelegate, RDPlayerDelegate>
#property (readonly) Rdio *rdio;
#end
And in ViewController.m
- (IBAction)playButton:(UIButton *)sender
{
[self.rdio preparePlayerWithDelegate:nil];
NSArray *sources = [NSArray arrayWithObjects:#"t1", #"p1", #"a1", nil];
[self.rdio.player playSources:sources];
}
I really appreciate the help!
I resolved my issue. My issue was I wasn't calling the initializer initWithConsumerKey... that I had in my App Delegate. I had also failed to set it as a delegate properly.
So my App Delegate looks like this:
#import "AppDelegate.h"
static AppDelegate *launchedDelegate;
#interface AppDelegate ()
#end
#implementation AppDelegate
+ (Rdio *)rdioInstance
{
return launchedDelegate.rdio;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
launchedDelegate = self;
_rdio = [[Rdio alloc] initWithConsumerKey:#"removed" andSecret:#"removed" delegate:nil];
return YES;
}
and in ViewController.m:
- (IBAction)listenButton:(UIButton *)sender
{
_rdio = [AppDelegate rdioInstance];
[self.rdio preparePlayerWithDelegate:nil];
[self.rdio.player playSource:#"p12691138"];
}
Feeling silly that I didn't get that at first! Leaving it up here in case it helps anybody.

No visible #interface for [object] declares the selector [method]

I am a complete beginner at Objective c and I am trying to complete a challenge in the book "iOS programming: The big Nerd Ranch guide".
I'm trying to put an object called item (of the class BNRItem) into an NSMutableArray called subItems which is part of an object called container (of the class BNRContainer, a subclass of BNRItem with the addition of the NSMutableArray to hold BNRItems). BNRItem works fine.
The code is as follows:
BNRContainer.h
#import <Foundation/Foundation.h>
#import "BNRItem.h"
#interface BNRContainer : BNRItem
{
NSMutableArray *subItems;
}
BNRContainer.m
- (id)init
{
return [self initWithItemName:#"Container"
valueInDollars:0
serialNumber:#""];
}
- (void)setSubItems:(BNRItem*)item
{
[subItems addObject:item];
}
Main.m
#import <Foundation/Foundation.h>
#import "BNRItem.h"
#import "BNRContainer.h"
int main(int argc, const char * argv[])
{
#autoreleasepool {
BNRItem *item = [[BNRItem alloc] init];
BNRContainer *container = [[BNRContainer alloc] init];
[container setSubItems:item]
}
return 0;
}
At the line [container setSubItems:item] I get the error: No visible #interface for container declares the selector setSubItems
The setter method setSubItems doesn't code complete (although other setters do, and work fine).
Am I doing something simple wrong? A simple explanation would be very appreciated!
Update BNRContainer.h:
#import <Foundation/Foundation.h>
#import "BNRItem.h"
#interface BNRContainer : BNRItem
{
NSMutableArray *subItems;
}
- (void)setSubItems:(BNRItem*)item;
#end
(Dunno why Fred deleted his answer.)
In order for Xcode to generate the getters/setters for subItems, you have to actually declare the property for it in your interface. Something like this:
#import <Foundation/Foundation.h>
#import "BNRItem.h"
#interface BNRContainer : BNRItem
#property (strong, nonatomic) NSMutableArray *subItems;
#end
Additionally, you aren't ever actually alloc/initing your array, and the current logic for setSubItems: will not do what it sounds like it would do. This function would add the array passed as a parameter as an object within SubItems. If you're trying to add items from an array to subitems, then you should be using:
[myMutableArray addObjectsFromArray:<#(NSArray *)#>];

Resources