How do I attach a website to an app in Xcode using the UIWebView? The only chunk of code in the assistant editor is:
#import <UIKit/UIKit.h>
#interface XYZAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator
*persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
What would be the next step?
http://conecode.com/news/2011/05/ios-tutorial-creating-a-web-view-uiwebview/ Google is the answer to this question.
Related
I'm using React Native to make an iOS Application.
I need to add some code to AppDelegate.h file.
However, after searching about this, I realized that it's impossible to declare two interfaces at the same time.
How can I integrate these two interfaces?
// here's the code in AppDelegate.h
#interface AppDelegate : UMAppDelegateWrapper <RCTBridgeDelegate>
#property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
#property (nonatomic, strong) UIWindow *window;
#end
#interface AppDelegate : UIResponder <UIApplicationDelegate, AppsFlyerTrackerDelegate>
#end
Suposing that UMAppDelegateWrapper is a subclass of UIResponder, you can merge both as follows:
#interface AppDelegate : UMAppDelegateWrapper <UIApplicationDelegate, AppsFlyerTrackerDelegate,RCTBridgeDelegate>
#property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
#property (nonatomic, strong) UIWindow *window;
#end
I'm having an issue with a memory leak. In Instruments, I'm getting a memory leak on this line:
VDLPlaybackViewController *videoController = [[VDLPlaybackViewController alloc] initWithNibName:#"VDLPlaybackView" bundle:nil];
I'm not sure what could be the issue on this. Here is the header file for VDLPlaybackViewController.h:
#protocol VDLPlaybackViewControllerDelegate <NSObject>
#required
-(void)playerShouldClose;
#end
#interface VDLPlaybackViewController : UIViewController <UIDocumentInteractionControllerDelegate>
#property (nonatomic, strong) id<VDLPlaybackViewControllerDelegate> delegate;
// content file stuff.
#property (nonatomic, strong) File *file;
#property (nonatomic, strong) NSNumber *contentID;
#property (nonatomic, strong) NSURL *fileURL;
#property (nonatomic, strong) NSString *pageTitle;
// layout stuff
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *topTimeViewHeight;
#property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomControlViewHeight;
#property (nonatomic, strong) IBOutlet UIView *movieView;
#property (nonatomic, strong) IBOutlet UIView *navBarView;
#property (nonatomic, strong) IBOutlet UISlider *positionSlider;
#property (nonatomic, strong) IBOutlet UIButton *timeDisplay;
#property (nonatomic, strong) IBOutlet UIButton *playPauseButton;
#property (nonatomic, strong) IBOutlet UIButton *subtitleSwitcherButton;
#property (nonatomic, strong) IBOutlet UIButton *audioSwitcherButton;
#property (nonatomic, strong) IBOutlet UIButton *screenSizeSwitcherButton;
//#property (nonatomic, strong) IBOutlet UINavigationBar *toolbar;
#property (nonatomic, strong) IBOutlet UIView *controllerPanel;
#property (nonatomic, strong) IBOutlet UISlider *volumeSlider;
#property (nonatomic, strong) IBOutlet MPVolumeView *volumeView;
#property (nonatomic, strong) IBOutlet MPVolumeView *airplayView;
#property (nonatomic, assign) CGRect shareButtonFrame;
#property (nonatomic, strong) MultiFileShareButtonController *shareButtonController;
#property (nonatomic, strong) FavoriteFileButtonView *favoriteButtonController;
#property (nonatomic, strong) UIDocumentInteractionController *interactionController;
#property (nonatomic, assign) BOOL isDestroying;
- (void)setMediaURL:(NSURL*)theURL;
- (IBAction)closePlayback:(id)sender;
- (IBAction)positionSliderDrag:(id)sender;
- (IBAction)positionSliderAction:(id)sender;
- (IBAction)toggleTimeDisplay:(id)sender;
- (IBAction)playandPause:(id)sender;
//- (IBAction)switchAudioTrack:(id)sender;
//- (IBAction)switchSubtitleTrack:(id)sender;
- (IBAction)switchVideoDimensions:(id)sender;
#end
Does anyone know what causes this?
The instrumentation tool tells you that there is a leak on the following line:
VDLPlaybackViewController *videoController = [[VDLPlaybackViewController alloc] initWithNibName:#"VDLPlaybackView" bundle:nil];
It does not mean, that it's just this line which is causing the leak, the tool is telling you that a reference of this variable exists as a leak.
You should look for instances where a strong reference to VDLPlaybackViewController *videoController was passed.. may be as delegates or in completion blocks.
The interface which you have in the question has a little problem. It should be weak instead of strong
#property (nonatomic, weak) id<VDLPlaybackViewControllerDelegate> delegate;
Find more instances like this, where you've passed around VDLPlaybackViewController as a strong reference delegate and you would be able to resolve the problem.
To understand more on why the leak is actually happening. Go through
https://cocoacasts.com/what-are-strong-reference-cycles
I am receiving error like
: Unknown type name 'AppDelegate'
: Unknown type name 'AppDelegate'
: Property with 'weak' attribute must be of object type
I had refer many Question like this but all give answer like add
#class Appdelegate;
I tried with editing this code but after this it gives error like
: AppDelegate.m:23:18: Redefinition of 'ddLogLevel'
Because this log is define in both view controller. i have also tried to commented line of this log from above view controller but then it will give error
: /ChatViewController.m:440:13: Use of undeclared identifier 'ddLogLevel'
Now what is the solution for this?
EDIT: i have to declare like this. because i am working on xmpp. so i have to call [[self appDelegate] connect] method in another view controller.
- (AppDelegate *)appDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
EDIT
//Appdelegate.h file //
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "ViewController.h"
#import "MBProgressHUD.h"
#import "FriendsViewController.h"
#import <CoreData/CoreData.h>
#import "XMPPFramework.h"
//#class FriendsViewController;
#class ViewController;
#interface AppDelegate : NSObject <UIApplicationDelegate, XMPPRosterDelegate>
{
XMPPStream *xmppStream;
XMPPReconnect *xmppReconnect;
XMPPRoster *xmppRoster;
XMPPRosterCoreDataStorage *xmppRosterStorage;
XMPPvCardCoreDataStorage *xmppvCardStorage;
XMPPvCardTempModule *xmppvCardTempModule;
XMPPvCardAvatarModule *xmppvCardAvatarModule;
XMPPCapabilities *xmppCapabilities;
XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;
NSString *password;
BOOL customCertEvaluation;
BOOL isXmppConnected;
BOOL isauthenticate;
UIWindow *window;
UINavigationController *navigationController;
//SettingsViewController *loginViewController;
UIBarButtonItem *loginButton;
ViewController *viewController;
FriendsViewController *FriendsViewController;
}
#property (strong, nonatomic) UIWindow *window;
#property (nonatomic, strong, readonly) XMPPStream *xmppStream;
#property (nonatomic, strong, readonly) XMPPReconnect *xmppReconnect;
#property (nonatomic, strong, readonly) XMPPRoster *xmppRoster;
#property (nonatomic, strong, readonly) XMPPRosterCoreDataStorage *xmppRosterStorage;
#property (nonatomic, strong, readonly) XMPPvCardTempModule *xmppvCardTempModule;
#property (nonatomic, strong, readonly) XMPPvCardAvatarModule *xmppvCardAvatarModule;
#property (nonatomic, strong, readonly) XMPPCapabilities *xmppCapabilities;
#property (nonatomic, strong, readonly) XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;
//#property (nonatomic, strong) IBOutlet UIWindow *window;
#property (nonatomic, strong) IBOutlet UINavigationController *navigationController;
//#property (nonatomic, strong) IBOutlet SettingsViewController *settingsViewController;
#property (nonatomic, strong) IBOutlet UIBarButtonItem *loginButton;
#property (nonatomic, strong) ViewController *viewController;
#property (nonatomic, strong) FriendsViewController *FriendsViewController;
- (NSManagedObjectContext *)managedObjectContext_roster;
- (NSManagedObjectContext *)managedObjectContext_capabilities;
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (BOOL)connect;
- (BOOL) isXmppConnected;
- (void)disconnect;
-(BOOL) isauthenticate;
#end
You have two issues there, I will address them separately:
Unknown type name 'AppDelegate'
This occurs because of circular dependency: ChathistryViewController.h imports AppDelegate.h and vice-versa.
You can resolve this by importing AppDelegate.h only in ChathistryViewController.m and including #class AppDelegate in .h file.
AppDelegate.m:23:18: Redefinition of 'ddLogLevel'
When you are defining ddLogLevel in your *ViewController.h file, it's definition is "copied" to all files you import *ViewController.h.
You should import CocoaLumberjack and define ddLogLevel only in .m files, as they are not needed in .h anyway.
Appdelegate object should be created like this:
It is a singletone Class, where only one instance of the class exists for the current process.
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
So I have this -
#import <UIKit/UIKit.h>
#import "RateView.h"
#interface BasicCardViewController : UIViewController<RateViewDelegate>
#property (weak, nonatomic) IBOutlet UILabel *label;
#property(copy, nonatomic)NSString *message;
#property(atomic)NSInteger rating;
#property (strong, nonatomic) IBOutlet RateView *rateView;
#property (weak, nonatomic) IBOutlet UILabel *ratingLabel;
#end
and this - in my RateView.h file.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#class RateView;
#protocol RateViewDelegate
-(void)rateView:(RateView *)rateView ratingDidChange:(float)rating;
#end
#interface RateView : UIView
#property(strong,nonatomic)UIImage* fullSelectedStar;
#property(strong,nonatomic)UIImage* notSelectedStar;
#property(strong, nonatomic)UIImage* halfSelectedStar;
#property (assign, nonatomic)float rating;
#property(assign) BOOL editable;
#property (strong) NSMutableArray* imageViews;
#property(assign,nonatomic) int maxRating;
#property(assign) int midMargin;
#property(assign)int leftMargin;
#property (assign) CGSize minImageSize;
#property (assign) id <RateViewDelegate> delegate;
#end
But I get two errors -
1.Cannot find protocol declaration for 'TooviaRateViewDelegate'
2.Unknown type name "RateView"
I've tried to clean, and I've verified that the files are where they should be (their filepaths are to the project).
Why is this happening?
Edit - my AppDelegate.h
#import <UIKit/UIKit.h>
#import "SearchViewController.h"
#interface TooviaAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property NSOperationQueue *queue;
#property (strong, nonatomic) NSDictionary *userProfile;
#property (strong, nonatomic) SearchViewController *searchViewController;
- (NSOperationQueue*) getOperationQueue;
- (id)getSettings:(NSString *)keyPath;
- (void) saveCookies;
#end
There are also issues in my SearchViewController
#import <UIKit/UIKit.h>
#import "BasicCardViewController.h"
#interface SearchViewController : UIViewController
<UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDataSource, UITableViewDelegate>
- (IBAction)searchButtonClicked:(UIButton *)sender;
- (IBAction)backgroundTap:(id)sender;
#property (weak, nonatomic) IBOutlet UITableView *resultTable;
#property (weak, nonatomic) IBOutlet UITextField *searchBar;
#property (strong, nonatomic) NSArray *resultsTuples;
#property (weak, nonatomic) IBOutlet UIButton *searchButton;
#property (copy, nonatomic) NSArray *controllers;
#property(strong,nonatomic)BasicCardViewController *detailController;
Delegate and data source properties are usually marked as weak for the object graph management reasons described earlier, in “Avoid Strong Reference Cycles.”
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
Why iOS's auto-generated AppDelegate still declares its members as strong while I have chosen not to use ARC?
strong properties do not require ARC. strong is a synonym of retain.
From Transitioning to ARC Release Notes
// The following declaration is a synonym for: #property(retain) MyClass *myObject;
#property(strong) MyClass *myObject;