OpenFL расширение родной iOS (c ++, haxe, obj-c)

Я пытаюсь создать расширение, которое позволяет мне показывать предупреждающее сообщение с двумя кнопками в iOS с событиями дескриптора:

У меня проблема с частью obj-c каждый раз, когда я пытаюсь скомпилировать:

Я заблудился здесь (заметьте, я не очень уверен в obj-c):

Журнал:

NativeTest.mm
\f0\b0 \cf0  -oobj/iphoneos-v7/04964c13_NativeTest.o\

\f1\b \cf3 Error:
\f0\b0 \cf0
\f1\b ./iphone/NativeTest.mm:20:32: error: missing '[' at start of message send expression
\f0\b0 \

\f1\b         UIAlertView* alertView[[UIAlertView alloc] initWithTitle: [[NSString alloc]
\f0\b0 \

\f1\b                                ^
\f0\b0 \

\f1\b                                [
\f0\b0 \

\f1\b ./iphone/NativeTest.mm:25:107: warning: missing sentinel in method dispatch [-Wsentinel]
\f0\b0 \

\f1\b                                            otherButtonTitles: [[NSString alloc] initWithUTF8String:cancel]]
\f0\b0 \

\f1\b                                                                                                           ^
\f0\b0 \

\f1\b                                                                                                           , nil
\f0\b0 \

\f1\b /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAlertView.h:26:1: note: method has been explicitly marked sentinel here
\f0\b0 \

\f1\b - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION NS_EXTENSION_UNAVAILABLE_IOS("Use UIAlertController instead.");
\f0\b0 \

\f1\b ^
\f0\b0 \

\f1\b ./iphone/NativeTest.mm:27:9: error: expected ']'
\f0\b0 \

\f1\b         [alert show];
\f0\b0 \

\f1\b         ^
\f0\b0 \

\f1\b ./iphone/NativeTest.mm:20:31: note: to match this '['
\f0\b0 \

\f1\b         UIAlertView* alertView[[UIAlertView alloc] initWithTitle: [[NSString alloc]
\f0\b0 \

\f1\b                               ^
\f0\b0 \

\f1\b ./iphone/NativeTest.mm:20:32: error: size of array has non-integer type 'UIAlertView *'
\f0\b0 \

\f1\b         UIAlertView* alertView[[UIAlertView alloc] initWithTitle: [[NSString alloc]
\f0\b0 \

\f1\b                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\f0\b0 \

\f1\b 1 warning and 3 errors generated.
\f0\b0 \

\f1\b \cf2 xcrun
\f0\b0 \cf0  --sdk iphonesimulator8.1 clang++ -IiPhone/include -Iinclude -c -stdlib=libstdc++ -O2 -fmessage-length=0 -pipe -Wno-trigraphs -fno-stack-protector -fpascal-strings -fasm-blocks -Wreturn-type -Wno-unused-variable -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk -fvisibility=hidden -miphoneos-version-min=5.0
\f1\b -DIPHONE=IPHONE
\f0\b0
\f1\b -DIPHONESIM=IPHONESIM
\f0\b0  -Wno-parentheses -Wno-null-dereference -Wno-unused-value -Wno-bool-conversion
\f1\b -DSTATIC_LINK
\f0\b0
\f1\b -DHXCPP_VISIT_ALLOCS
\f0\b0
\f1\b -DHXCPP_API_LEVEL=0
\f0\b0  -I/Users/henriknielsen/Desktop/Stencyl-3.0/plaf/haxe/lib/hxcpp/3,1,39/include -x objective-c++ -fobjc-abi-version=2 -fobjc-legacy-dispatch \cf2 ./iphone/
\f1\b NativeTest.mm
\f0\b0 \cf0  -oobj/iphonesim/aa8846ca_NativeTest.o\

\f1\b \cf3 Error:
\f0\b0 \cf0
\f1\b ./iphone/NativeTest.mm:20:32: error: missing '[' at start of message send expression
\f0\b0 \

\f1\b         UIAlertView* alertView[[UIAlertView alloc] initWithTitle: [[NSString alloc]
\f0\b0 \

\f1\b                                ^
\f0\b0 \

\f1\b                                [
\f0\b0 \

\f1\b ./iphone/NativeTest.mm:25:107: warning: missing sentinel in method dispatch [-Wsentinel]
\f0\b0 \

\f1\b                                            otherButtonTitles: [[NSString alloc] initWithUTF8String:cancel]]
\f0\b0 \

\f1\b                                                                                                           ^
\f0\b0 \

\f1\b                                                                                                           , nil
\f0\b0 \

\f1\b /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAlertView.h:26:1: note: method has been explicitly marked sentinel here
\f0\b0 \

\f1\b - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION NS_EXTENSION_UNAVAILABLE_IOS("Use UIAlertController instead.");
\f0\b0 \

\f1\b ^
\f0\b0 \

\f1\b ./iphone/NativeTest.mm:27:9: error: expected ']'
\f0\b0 \

\f1\b         [alert show];
\f0\b0 \

\f1\b         ^
\f0\b0 \

\f1\b ./iphone/NativeTest.mm:20:31: note: to match this '['
\f0\b0 \

\f1\b         UIAlertView* alertView[[UIAlertView alloc] initWithTitle: [[NSString alloc]
\f0\b0 \

\f1\b                               ^
\f0\b0 \

\f1\b ./iphone/NativeTest.mm:20:32: error: size of array has non-integer type 'UIAlertView *'
\f0\b0 \

\f1\b         UIAlertView* alertView[[UIAlertView alloc] initWithTitle: [[NSString alloc]
\f0\b0 \

\f1\b                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\f0\b0 \

\f1\b 1 warning and 3 errors generated.

Вот часть из моего NativeTest.mm

#include <NativeTest.h>
#import <UIKit/UIKit.h>
#import <CoreFoundation/CoreFoundation.h>

using namespace nativetest;
@interface nativetestController : UIAlertView <UIAlertViewDelegate>
{
}

@end

@implementation nativetestController
namespace nativetest
{

void showSystemAlert(const char *title, const char *message, const char *ok, const char *cancel)
{
UIAlertView* alertView[[UIAlertView alloc] initWithTitle: [[NSString alloc]
initWithUTF8String:title]
message: [[NSString alloc] initWithUTF8String:message]
delegate: NULL
cancelButtonTitle: [[NSString alloc] initWithUTF8String:ok]
otherButtonTitles: [[NSString alloc] initWithUTF8String:cancel]]

[alert show];

}
}- (void) alertView: (UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
//Code for OK button
bool pressid = YES;

}
if (buttonIndex == 1)
{
//Code for download button
bool pressid = NO;
}
}@end

Мой NativeTest.h

#ifndef NativeTest
#define NativeTestnamespace nativetest
{
void showSystemAlert(const char* title, const char* message, const char* ok, const char* cancel);
bool pressid();
}

#endif

ExternalInterface.cpp

#if defined(HX_WINDOWS) || defined(HX_MACOS) || defined(HX_LINUX)
#define NEKO_COMPATIBLE
#endif

#include <hx/CFFI.h>
#include "NativeTest.h"#include <stdio.h>

using namespace nativetest;#ifdef IPHONE

//--------------------------------------------------
// Glues Haxe to native code.
//--------------------------------------------------

void ios_alert(value title, value message, value ok, value cancel)
{
showSystemAlert(val_string(title), val_string(message), val_string(ok), val_string(cancel));
}
DEFINE_PRIM(ios_alert, 4);

static value getpressid()
{
if (nativetest::pressid())
return val_true;
return val_false;
}
DEFINE_PRIM(getpressid, 0);

#endif//--------------------------------------------------
// IGNORE STUFF BELOW THIS LINE
//--------------------------------------------------

extern "C" void nativetest_main()
{
}
DEFINE_ENTRY_POINT(nativetest_main);

extern "C" int nativetest_register_prims()
{
return 0;
}

NativeTest.hx

 package;

#if cpp
import cpp.Lib;
#elseif neko
import neko.Lib;
#else
import nme.Lib;
#end

#if android
import nme.JNI;
#end

class NativeTest
{
private static var pressid:Bool = false;
private static var title:String;
private static var message:String;
private static var ok:String;
private static var cancel:String;

public static function showAlert(title:String, message:String, ok:String, cancel:String):Void
{
NativeTest.title = title;
NativeTest.message = message;
NativeTest.ok = ok;
NativeTest.cancel = cancel;
NativeTest.pressid = pressid;
haxe.Timer.delay(delayAlert, 30);
}

private static function delayAlert():Void
{
#if(cpp && mobile && !android)
iosAlert(title, message, ok, cancel);
#end

#if android
if(androidAlert == null)
{
androidAlert = nme.JNI.createStaticMethod("NativeTest", "showAlert", "(Ljava/lang/String;Ljava/lang/String;)V", true);
}

androidAlert([title, message]);
#end
}

#if android
private static var androidAlert:Dynamic;
#end

#if(cpp && mobile && !android)
static var iosAlert = nme.Loader.load("ios_alert", 4);
private static var pressid = nme.Loader.load("getpressid",0);
#end
public static function getpressid(pressid:Int):Bool
{
if (pressid == 0)
{
#if ios
return pressid();
#end

}
else
{
#if ios
return pressid();
#end
}
}
}

0

Решение

Сообщения об ошибках указывают, что компилятор хочет открывающую скобку.

Вы скопировали свой код точно так же, как в вашем приложении? Со стороны Objective-C, похоже, что отсутствуют некоторые вещи, а именно оператор присваивания «=», «nil», чтобы указать конец опций для otherButtonTitles, и
«;» в конце вызова метода.

Для компилятора все, от «UIAlertView *» до «[show alertview];» выглядит как одно утверждение.

Кстати, вы также можете использовать [NSString stringWithUTF8String:] вместо выделения / инициализации всех строк. Тот же эффект, меньше кода:

    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithUTF8String:title]
message:[NSString stringWithUTF8String:message]
delegate:NULL
cancelButtonTitle:[NSString stringWithUTF8String:ok]
otherButtonTitles:[NSString stringWithUTF8String:cancel], nil];
0

Другие решения


По вопросам рекламы [email protected]