Error : No matching function for call to 'RCTAppSetupDefaultRootView' - xcode

After updating to React Native version 0.71.2, I received the following error message:
'No matching function for call to 'RCTAppSetupDefaultRootView'
Do you know where this problem could come from?
here my AppDelegate.mm :
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTAppSetupUtils.h>
#import <Firebase.h>
#if RCT_NEW_ARCH_ENABLED
#import <React/CoreModulesPlugins.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <react/config/ReactNativeConfig.h>
static NSString *const kRNConcurrentRoot = #"concurrentRoot";
#interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
RCTTurboModuleManager *_turboModuleManager;
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
facebook::react::ContextContainer::Shared _contextContainer;
}
#end
#endif
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
#if RCT_NEW_ARCH_ENABLED
_contextContainer = std::make_shared<facebook::react::ContextContainer const>();
_reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
[FIRApp configure];
#endif
NSDictionary *initProps = [self prepareInitialProps];
UIView *rootView = RCTAppSetupDefaultRootView(bridge, #"XplosionTMBD", initProps);
if (#available(iOS 13.0, *)) {
rootView.backgroundColor = [UIColor systemBackgroundColor];
} else {
rootView.backgroundColor = [UIColor whiteColor];
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// #see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// #note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// #return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
// Switch this bool to turn on and off the concurrent root
return true;
}
- (NSDictionary *)prepareInitialProps
{
NSMutableDictionary *initProps = [NSMutableDictionary new];
#ifdef RCT_NEW_ARCH_ENABLED
initProps[kRNConcurrentRoot] = #([self concurrentRootEnabled]);
#endif
return initProps;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:#"index"];
#else
return [[NSBundle mainBundle] URLForResource:#"main" withExtension:#"jsbundle"];
#endif
}
#if RCT_NEW_ARCH_ENABLED
#pragma mark - RCTCxxBridgeDelegate
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
delegate:self
jsInvoker:bridge.jsCallInvoker];
return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
}
#pragma mark RCTTurboModuleManagerDelegate
- (Class)getModuleClassFromName:(const char *)name
{
return RCTCoreModulesClassProvider(name);
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
{
return nullptr;
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
initParams:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return nullptr;
}
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
{
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}
#endif
#end
here my nix react-native info
System:
OS: macOS 12.5.1
CPU: (8) arm64 Apple M1
Memory: 201.66 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.12.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.19.2 - /usr/local/bin/npm
Watchman: 2023.02.06.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 14.2/14C18 - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
#react-native-community/cli: ^10.1.3 => 10.1.3
react: ^18.2.0 => 18.2.0
react-native: 0.71.2 => 0.71.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Any help will be appreciated.
thank you
I tried to downgrade and re-upgrade react native
I tried to de-integrate and re-install pods
I tried to re-install NPM package
I followed the react upgrade documentation
I wanted a build success but my build continues to fail

RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties, BOOL fabricEnabled)
You are missing 1 parameter.

Related

Warning on XCodeGLKit deprecated consider migrating to Metal instead and Apple email Deprecated API Usage, use WKWebView instead of UIWebView

I've completed my game using Buildbox 2.3.3 and have cleaned up as many warnings as possible on Xcode. However, I've been at this for weeks now on me migrating from OpenGL to Metal which I assume is the reason I have that error in Xcode saying GLKit is deprecated, consider migrating to metal instead.
I attempted to upload the game to App store connect without me solving this error but then I instantly got sent an email saying
ITMS-90809: Deprecated API Usage, New apps no longer use UIWebView,
use WKWebView instead.
I've no clue how to go about converting my code to cater for this I would really appreciate some guidance or if anyone can rewrite my code for me converting the OpenGL to metal.
I'll attach the code I'm using below, I would really appreciate it if anyone can help me. I've been stuck at this final stage for weeks now, its very frustrating.
AppDelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>{
}
#property (strong, nonatomic) UIWindow *window;
#end
AppDelegate.mm
#import "AppDelegate.h"
#import <GLKit/GLKit.h>
#include "PTPSettingsController.h"
#include "libs/cocos2dx/include/audio/include/SimpleAudioEngine.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
cocos2d::CCDirector::sharedDirector()->pause();
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
cocos2d::CCApplication::sharedApplication()->applicationDidEnterBackground();
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground();
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
cocos2d::CCDirector::sharedDirector()->resume();
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
- (void)loadingDidComplete{
}
-(void)showCustomFullscreenAd{
}
- (void)screenOnEnter:(const char*) name{
}
- (void)screenOnExit:(const char*) name{
}
#end
GameViewController.h
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
#interface GameViewController : GLKViewController
#end
GameViewController.mm
#import "GameViewController.h"
#import <OpenGLES/ES2/glext.h>
#import "PTModelController.h"
#import "PTModelGeneralSettings.h"
#import "PTPAppDelegate.h"
#import "cocos2d.h"
#import "PTPConfig.h"
#include "PTPSettingsController.h"
#define IOS_MAX_TOUCHES_COUNT 10
static PTPAppDelegate s_sharedApplication;
#interface GameViewController () {
NSString* shareMessage;
bool sheduledForShareWidget;
}
#property (strong, nonatomic) EAGLContext *context;
#end
#implementation GameViewController
- (void)viewDidLoad{
[super viewDidLoad];
sheduledForShareWidget = false;
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!self.context) {
NSLog(#"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[view setMultipleTouchEnabled: YES];
[self setPreferredFramesPerSecond:60];
[EAGLContext setCurrentContext:self.context];
PTModelController *mc = PTModelController::shared();
mc->clean();
unsigned long size = 0;
char* pBuffer = (char*)CCFileUtils::sharedFileUtils()->getFileData("data/data.pkg", "rb", &size);
if (pBuffer != NULL && size > 0){
mc->setUsingDataEncryption( true );
}
mc->loadDataForSplashScreen("data/data.pkg", processor().c_str());
s_sharedApplication.setDataArchiveProcessor(processor());
cocos2d::CCApplication::sharedApplication()->run();
}
- (void)dealloc{
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
if ([self isViewLoaded] && ([[self view] window] == nil)) {
self.view = nil;
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
// Dispose of any resources that can be recreated.
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cocos2d::CCDirector::sharedDirector()->setViewport();
cocos2d::CCDirector::sharedDirector()->mainLoop();
}
- (void)update{
if(sheduledForShareWidget == true){
sheduledForShareWidget = false;
GLKView *view = (GLKView *)self.view;
UIImage* screenshot = view.snapshot;
PTLog("Opens Share Widget: screenshot was taken");
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:#[shareMessage, screenshot] applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypeSaveToCameraRoll,
UIActivityTypeAssignToContact];
activityVC.excludedActivityTypes = excludeActivities;
float iOSVersion = [[UIDevice currentDevice].systemVersion floatValue];
if(iOSVersion > 8.0){
activityVC.popoverPresentationController.sourceView = self.view;
}
[self presentViewController:activityVC animated:YES completion:nil];
PTLog("opens Share Widget: view controller presented");
}
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
int ids[IOS_MAX_TOUCHES_COUNT] = {0};
float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};
int i = 0;
for (UITouch *touch in touches) {
ids[i] = (intptr_t)touch;
xs[i] = [touch locationInView: [touch view]].x * self.view.contentScaleFactor;
ys[i] = [touch locationInView: [touch view]].y * self.view.contentScaleFactor;
++i;
}
cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesBegin(i, ids, xs, ys);
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
int ids[IOS_MAX_TOUCHES_COUNT] = {0};
float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};
int i = 0;
for (UITouch *touch in touches) {
ids[i] = (intptr_t)touch;
xs[i] = [touch locationInView: [touch view]].x * self.view.contentScaleFactor;;
ys[i] = [touch locationInView: [touch view]].y * self.view.contentScaleFactor;;
++i;
}
cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesMove(i, ids, xs, ys);
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
int ids[IOS_MAX_TOUCHES_COUNT] = {0};
float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};
int i = 0;
for (UITouch *touch in touches) {
ids[i] = (intptr_t)touch;
xs[i] = [touch locationInView: [touch view]].x * self.view.contentScaleFactor;;
ys[i] = [touch locationInView: [touch view]].y * self.view.contentScaleFactor;;
++i;
}
cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesEnd(i, ids, xs, ys);
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
int ids[IOS_MAX_TOUCHES_COUNT] = {0};
float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};
int i = 0;
for (UITouch *touch in touches) {
ids[i] = (intptr_t)touch;
xs[i] = [touch locationInView: [touch view]].x * self.view.contentScaleFactor;;
ys[i] = [touch locationInView: [touch view]].y * self.view.contentScaleFactor;;
++i;
}
cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesCancel(i, ids, xs, ys);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
PTModelGeneralSettingsPtr generalSettings = PTModelGeneralSettings::shared();
if(generalSettings->orientation() == PTModelGeneralSettings::LandscapeOrientation){
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}
else if(generalSettings->orientation() == PTModelGeneralSettings::PortraitOrientation){
return UIInterfaceOrientationIsPortrait( interfaceOrientation );
}
return NO;
}
- (NSUInteger) supportedInterfaceOrientations{
PTModelGeneralSettingsPtr generalSettings = PTModelGeneralSettings::shared();
if(generalSettings->orientation() == PTModelGeneralSettings::LandscapeOrientation){
return UIInterfaceOrientationMaskLandscape;
}
else if(generalSettings->orientation() == PTModelGeneralSettings::PortraitOrientation){
return UIInterfaceOrientationMaskPortrait;
}
return NO;
}
- (BOOL) shouldAutorotate {
return NO;
}
-(void) scheduleOpenShareWidget:(const char*) message{
shareMessage = [NSString stringWithUTF8String:message];
sheduledForShareWidget = true;
}
#end
As you've already been told, your question is a little unsuitable for Stack Overflow. You can start rewriting your project from OpenGL to Metal, and ask questions if anything goes wrong.
Apple documentation is a good starting point:
Migrating OpenGL Code to Metal
Mixing Metal and OpenGL Rendering in a View
You could also watch WWDC 2019 video and learn a step-by-step approach for transitioning OpenGL-based apps to the Metal API.
OpenGL is portable and widely supported, so it's a pity not to be able to use it. Luckily the MetalANGLE framework is an almost perfect drop-in replacement for GLKit. I have started using it in the development branch of my map rendering library, CartoType, and it works correctly: I can't see any difference in the graphics compared to GLKit, and I had to make only one minor change to my code to get it working - and that change was probably caused by an incorrect use of GLKit.
So my advice is: stay with OpenGL and use MetalANGLE.

Backward compatibility of Xcode OSX

How to use features such as viewDidLoad or appDidBecomeActive in Xcode 4.6.1 for OSX 10.8, which are available only for OSX 10.10 and above. Please suggest the alternative ways to use these functions.
To expand on Ken Thomas's comment; this is the code that I use:
- (void)loadView
{
[super loadView];
// if we're running on 10.8 or older…
if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_8) {
[self viewDidLoad]; // call viewDidLoad (added in 10.9)
}
}
//
// This will be called by loadView pre-10.9; directly otherwise
//
- (void)viewDidLoad {
// --- YOUR CODE HERE ---
} // viewDidLoad
I'd override setView
#interface MyViewController : NSViewController
#end
#implementation MyViewController
- (void)setView:(NSView*)v {
super.view = v;
// if we're running on 10.8 or older…
if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_8) {
[self viewDidLoad]; // call viewDidLoad (added in 10.9)
}
}
#end

Can't restore purchases on Mac

I have problems with restoring purchases on Mac.
I've set up Itunesconnect app, in-app purchases, test user. I can buy items. If I buy the same non-consumable item multiple times, system will say that it has already bought and I will get it for free. But the problem in restoring.
Here is the code:
AppDelegate.h
#import <Cocoa/Cocoa.h>
#import <StoreKit/StoreKit.h>
#interface AppDelegate : NSObject <NSApplicationDelegate, SKProductsRequestDelegate, SKPaymentTransactionObserver>
{
NSArray *m_productIdentifiers;
NSArray* m_products;
}
-(IBAction)Press1:(id)sender;
-(IBAction)Press2:(id)sender;
#property (assign) IBOutlet NSWindow *window;
#end
AppDelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *receiptPath = [[[NSBundle mainBundle] appStoreReceiptURL] path];
if (![[NSFileManager defaultManager] fileExistsAtPath:receiptPath])
{
exit(173);
}
NSURL *url = [[NSBundle mainBundle] URLForResource:#"products"
withExtension:#"plist"];
m_productIdentifiers = [NSArray arrayWithContentsOfURL:url];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
-(IBAction)Press1:(id)sender
{
[self validateProductIdentifiers:m_productIdentifiers];
return;
}
-(IBAction)Press2:(id)sender
{
[self restorePurchases];
}
- (void)validateProductIdentifiers:(NSArray *)productIdentifiers
{
SKProductsRequest *productsRequest = [[SKProductsRequest alloc]
initWithProductIdentifiers:[NSSet setWithArray:productIdentifiers]];
productsRequest.delegate = self;
[productsRequest start];
}
- (void)productsRequest:(SKProductsRequest *)request
didReceiveResponse:(SKProductsResponse *)response
{
m_products = response.products;
for (NSString *dentifier in response.products)
{
NSLog(#"%#",dentifier);
}
}
- (void)requestDidFinish:(SKRequest *)request
{
NSLog(#"requestDidFinish");
return;
}
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
NSLog(#"request");
return;
}
- (void)restorePurchases
{
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction * transaction in transactions) {
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
};
}
- (void)completeTransaction:(SKPaymentTransaction *)transaction {
NSLog(#"completeTransaction...");
NSLog(#"completeTransaction... %#",transaction.payment.productIdentifier);
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
NSLog(#"restoreTransaction...");
NSLog(#"restoreTransaction... %#",transaction.payment.productIdentifier);
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (void)failedTransaction:(SKPaymentTransaction *)transaction {
NSLog(#"failedTransaction...");
if (transaction.error.code != SKErrorPaymentCancelled)
{
NSLog(#"Transaction error: %#", transaction.error.localizedDescription);
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
NSLog(#"restoreCompletedTransactionsFailedWithError: %#", error);
}
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSLog(#"paymentQueueRestoreCompletedTransactionsFinished");
}
#end
Press1 working great. I retrieve all my product ids. But after activating Press2 (Restoring) system asks password, and then the function - (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error is called.
The Console says:
11/27/13 4:19:00.022 PM storeagent: promptResponse: <CKSignInPromptResponse:0x7fdefca0b950 returnCode:1>
11/27/13 4:19:00.552 PM storeagent: LoadCompletedMicroPaymentsOperation: Could not install receipt after fetching completed purchases - Error Domain=ISErrorDomain Code=2 "No receipt." UserInfo=0x7fdefca183f0 {NSLocalizedDescription=No receipt., NSLocalizedFailureReason=receiptAsString was nil}
11/27/13 4:19:00.554 PM ***mac: restoreCompletedTransactionsFailedWithError: Error Domain=SKErrorDomain Code=0 "Unknown Error." UserInfo=0x1001e7190 {NSLocalizedDescription=Unknown Error.}
I've signed app with Distribution cert (3rd Party Mac Developer Application: ***).
Sandbox mode disabled, but I don't think that it is a source of the problem.
I haven't included embedded.provisionprofile in the build, but I don't think I need it now.
Xcode 4.6.3 + Mac OS 10.7.4
Xcode 5.0 + Mac OS 10.8.4
So, I've finally found the solution. The problem was in test users. Maybe, because they were created when we didn't have Mac developer program (only ios), but after creating new test user, problem dissappeared.

How do I develop for the iPad mini with Cordova/Phonegap?

I want to develop for the iPad Mini, but the simulator doesn't come with the Xcode 4.5. Is there any way I can see what my app is going to look like on the new iPad Mini? I am using the Cordova framework.
There is a simulator - it's called the iPad simulator. The iPad mini has the same resolution as the iPad. The only difference is the pixel density - i.e. the iPad mini has a greater pixel density than the iPad.
Go to your AppDelegate.m file and replace it with the code here:
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
//
// AppDelegate.m
// YOUR PROJECT NAME HERE
//
// Created by YOUR NAME HERE
// Copyright YOUR NAME HERE 2012. All rights reserved.
//
#import "AppDelegate.h"
#import "MainViewController.h"
#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVURLProtocol.h>
#else
#import "CDVPlugin.h"
#import "CDVURLProtocol.h"
#endif
#implementation AppDelegate
#synthesize window, viewController;
- (id) init
{
/** If you need to do any extra app-specific initialization, you can do it here
* -jm
**/
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
[CDVURLProtocol registerURLProtocol];
return [super init];
}
#pragma UIApplicationDelegate implementation
/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
*/
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString* invokeString = nil;
if (url && [url isKindOfClass:[NSURL class]]) {
invokeString = [url absoluteString];
NSLog(#"YOUR PROJECT NAME HERE launchOptions = %#", url);
}
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.autoresizesSubviews = YES;
CGRect viewBounds = [[UIScreen mainScreen] applicationFrame];
self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = #"www";
self.viewController.startPage = #"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;
// check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
BOOL forceStartupRotation = YES;
UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationUnknown == curDevOrientation) {
// UIDevice isn't firing orientation notifications yet… go look at the status bar
curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}
if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
for (NSNumber *orient in self.viewController.supportedOrientations) {
if ([orient intValue] == curDevOrientation) {
forceStartupRotation = NO;
break;
}
}
}
if (forceStartupRotation) {
NSLog(#"supportedOrientations: %#", self.viewController.supportedOrientations);
// The first item in the supportedOrientations array is the start orientation (guaranteed to be at least Portrait)
UIInterfaceOrientation newOrient = [[self.viewController.supportedOrientations objectAtIndex:0] intValue];
NSLog(#"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation);
[[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
}
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
CGFloat scale = 4.71f/5.82f;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
self.window.transform = CGAffineTransformConcat(scaleTransform, self.window.transform);
self.window.clipsToBounds = YES;
[self statusBarChanged:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(statusBarChanged:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
return YES;
}
- (void)statusBarChanged:(NSNotification *)note {
CGFloat scale = 4.71f/5.82f;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
UIWindow *statusBarWindow = (UIWindow *)[[UIApplication sharedApplication] valueForKey:#"statusBarWindow"];
statusBarWindow.transform = CGAffineTransformConcat(scaleTransform, statusBarWindow.transform);
}
- (void)keyboardWillShow:(NSNotification *)note {
[self performSelector:(#selector(doMagicToKeyboard)) withObject:nil afterDelay:0];
}
-(void)doMagicToKeyboard {
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
[self checkForKeyboard:window];
}
}
- (void)checkForKeyboard:(UIView *)view {
static BOOL didIt = NO;
for (UIView *currentView in view.subviews) {
if(([[currentView description] hasPrefix:#"<UIKeyboard"] == YES) && !didIt)
{
didIt = YES;
UIView *thisView = currentView.superview.superview;
thisView.clipsToBounds = YES;
CGFloat scale = 4.71f/5.82f;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
thisView.transform = CGAffineTransformConcat(scaleTransform, thisView.transform);
} else {
[self checkForKeyboard:currentView];
}
}
}
// this happens while we are running ( in the background, or from within our own app )
// only valid if Ipad Mini-Info.plist specifies a protocol to handle
- (BOOL) application:(UIApplication*)application handleOpenURL:(NSURL*)url
{
if (!url) {
return NO;
}
// calls into javascript global function 'handleOpenURL'
NSString* jsString = [NSString stringWithFormat:#"handleOpenURL(\"%#\");", url];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
// all plugins will get the notification, and their handlers will be called
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
return YES;
}
- (void) dealloc
{
[super dealloc];
}
#end
This will help people who want to develop for the iPad Mini; giving them a chance to see exactly what their app will look like on the new iPad Mini. This would not be possible without the great article I read on Michael Slaters blog. Here's the post where he walked me through the process of doing this for Cordova applications. Thanks Michael!
http://blog.michaelslater.net/making-your-ipad-app-mini.html?fb_comment_id=fbc_396351297103051_3342141_397114960360018#f35ee51728

On Snow Leopard, why is -[<ABImageClient> consumeImageData:forTag:] not being called after [ABPerson beginLoadingImageDataForClient:] is called?

I'm trying to load image date for person entries in the shared ABAddressBook. In particular, I'm calling
-[ABPerson beginLoadingImageDataForClient:]
and passing as the argument an object which adopts ABImageClient and implements
-[<ABPersonClient> consumeImageData:forTag:]
The approach I'm using works fine on Mountain Lion, but fails on Snow Leopard. In particular, -consumeImageData:forTag: never gets called.
The following sample command line program demonstrates my approach:
#import <Foundation/Foundation.h>
#import <AddressBook/AddressBook.h>
#interface ImageConsumer : NSObject <ABImageClient>
#property (nonatomic, strong) NSMutableDictionary *imagesForNumbers;
#end
#implementation ImageConsumer
- (id)init
{
self = [super init];
if (self) {
self.imagesForNumbers = [NSMutableDictionary dictionary];
}
return self;
}
- (void)consumeImageData:(NSData *)data forTag:(NSInteger)tag
{
[self.imagesForNumbers setObject:data forKey:[NSNumber numberWithInteger:tag]];
NSLog(#"%s: loaded data of length %zu for tag %zd", __PRETTY_FUNCTION__, data.length, tag);
}
#end
int main(int argc, const char * argv[])
{
#autoreleasepool {
NSArray *persons = [[ABAddressBook sharedAddressBook] people];
ImageConsumer *imageConsumer = [[ImageConsumer alloc] init];
for (ABPerson *person in persons) {
NSInteger loadingKey = [person beginLoadingImageDataForClient:imageConsumer];
NSLog(#"requested data person named %# %# and received tag %zd", [person valueForProperty:kABFirstNameProperty], [person valueForProperty:kABLastNameProperty], loadingKey);
}
[[NSRunLoop mainRunLoop] run];
}
return 0;
}
Am I misusing the ABAddressBook calls for loading image data for instances of ABPerson? Is this a bug with ABAddressBook on Snow Leopard? If so, is there a work-around?

Resources