How to use Objective-C framework in Swift without Bridging Header? - objective-c

I'm developing a Flutter plugin (in Swift) trying to wrap an Obj-C framework. I was able to import the Header files in MyPlugin.h file, but now how do I use the framework without a Bridging Header? I'm just getting not found in scope.
If I were to generate a Bridging Header, I ran into another error using bridging headers with framework targets is unsupported
This is my podspec file, I had to set DEFINES_MODULE to NO in order to build the project without running into Include of non-modular header inside framework module error
Pod::Spec.new do |s|
s.name = 'lisnr'
s.version = '1.0.0'
s.summary = 'Flutter plugin for LISNR'
s.description = <<-DESC
Flutter plugin for LISNR.
DESC
s.homepage = 'redacted'
s.license = { :file => '../LICENSE' }
s.author = { 'redacted' => 'redacted' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '8.0'
s.preserve_paths = 'radius.framework'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework radius' }
s.vendored_frameworks = 'radius.framework'
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'NO', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.swift_version = '5.0'
s.public_header_files = 'Classes/**/*.h'
end
The other codes are pretty much generated by the Flutter CLI.

You need a module map. You can either write it manually and put in the framework or do it with a script. See how I did it here for the Spotify SDK which is an ObjC framework.
The script for you would be something like that:
#!/bin/sh
MODULE_DIR="MY_PATH/radius.framework" # You framework's path
mkdir -p "${MODULE_DIR}"
printf "module radius {\n\
header \"Headers/radius.h\"\n\
export *\n\
}" > "${MODULE_DIR}/module.map"

Related

Github api with PHP

Im new in php and im trying to make a script who will create a new repository in github and catch a document that i have in my pc and make a commit in this new repository. This script will be executed in cmd. I search for github api and I have downloaded any folders with several files, i installed some things with a composer, but i cant create a new instance of github in my php.
I don't know anything about this, I spend two days in this and i cant write a function to talk with github. In the site of github developer I dont understand anything, I really need to do this, and im very lost. Im using PhpStorm 6.0.3.
What i cant understand:
1- The api is a folder with a lot of files? Or is a library who is imported in the phpstorm? How i put this in the phpstorm for i can get the methods and create my functions?
2- Where i get the methods for talk with the github api? Where i can see them? In github developer i dont understand nothing.
I see a question similar, but dont help me much.
Please help me
EDIT
I downloaded an api, and i use the composer require, apparently everything is fine, but when i execute some file to test the api, the same error pops up. The program cant find some files that is in the project, in the same folder.
Ex: PHP Fatal error: Interface 'Github\Api\ApiInterface' not found in D:\php-github-api-master\lib\Github\Api\AbstractApi.php on line 15
In anothers files the same error appears, i put "use" referecing the files that im trying to use, but dont work. Ex: use Github\Api\ApiInterface;
EDIT
This code will create a new repository right? When i execute this code I get the error above, Class 'Github\Api\AbstractApi' not found, but the class is in there.
class Repo extends AbstractApi
{
public function create(
$name,
$description = '',
$homepage = '',
$public = true,
$organization = null,
$hasIssues = false,
$hasWiki = false,
$hasDownloads = false,
$teamId = null,
$autoInit = false
) {
$path = null !== $organization ? 'orgs/'.$organization.'/repos' : 'user/repos';
$parameters = array(
'name' => $name,
'description' => $description,
'homepage' => $homepage,
'private' => !$public,
'has_issues' => $hasIssues,
'has_wiki' => $hasWiki,
'has_downloads' => $hasDownloads,
'auto_init' => $autoInit
);
if ($organization && $teamId) {
$parameters['team_id'] = $teamId;
}
return $this->post($path, $parameters);
}
}
Thanks,
Johann.
I finish my script, everything was done correct, sorry for my obviosly questions and thanks for who was answer me. My code:
<?php
include "vendor/autoload.php";
$client = new \Github\Client();
$username = "JohannLucas";
$password = "mypassword";
$method = Github\Client::AUTH_HTTP_PASSWORD;
//authenticate
$client->authenticate($username, $password, $method);
//Apagar Repositório
//$client->api('repo')->remove('JohannLucas', 'teste');
//Criar Repositório
$client->api('repo')->create('olamundo', 'Repositorio criado com o github api', 'http://my-repo-homepage.org', true);
//Commit
$committer = array('name' => 'JohannLucas', 'email' => 'johann.lucas#hotmail.com');
$path = "teste.txt";
$commitMessage = "Commit do teste.txt";
$content = "Olá Mundo!";
$branch = "master";
$repo = "olamundo";
$fileInfo = $client->api('repo')->contents()->create('JohannLucas', 'olamundo', $path, $content, $commitMessage, $branch, $committer);
print_r("Foi!");
Thanks!
Johann

CocoaPods Header Search

I'm experiencing what would seem a very basic problem and that is header files not being found. Below is a basic directory structure for a test POD I've created, my requirement is to retain the directory structure and for both root and SubPods to have access to header files. To retain the directory structure I'm using SubPods, if none of the classes make any reference to other classes the POD validates and the structure is correct. But if TSTSubClasses1.h includes TSTRootClass.h the POD lint validation fails 'fatal error: 'TSTRootClass.h' file not found.
Classes/TSTRootClass.h
Classes/TSTRootClass.m
Classes/SubPod-1/TSTSubClass1.h
Classes/SubPod-1/TSTSubClass1.m
Classes/SubPod-2/TSTSubClass2.h
Classes/SubPod-2/TSTSubClass2.m
I've tried various combinations of public_header_files, preserve_paths & s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/**'} but no luck. Is there any where that explains how to resolve search issues, also is there any way of outputting PATH details?
Detailed below is the podspec file, the source has been pushed to the repo and the structure and files do exist.
Pod::Spec.new do |s|
s.name = "PODTest"
s.version = "0.1.0"
s.summary = "PODTest dg dghjghj fghj ."
s.description = <<-DESC
sdfg sdfg adfg sdfgn of PODTest
DESC
s.homepage = "http://myhomepage"
s.license = 'MIT'
s.author = { "Duncan Hill" => "myemail#somedomain.com" }
#s.source = { :git => "git#bitbucket.org:reponame/podtest.git"}
s.source = { :git => "git#bitbucket.org:reponame/podtest.git", :tag => s.version.to_s }
s.platform = :ios, '5.0'
s.ios.deployment_target = '5.0'
s.requires_arc = true
#s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/#{s.name}/**'}
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/**'}
s.source_files = "Classes/*.{h,m}"
s.preserve_paths = "Classes/*"
s.subspec "SubPod-1" do |ss|
ss.public_header_files = "Classes/*.h"
ss.source_files = "Classes/SubPod-1/*.{h,m}"
end
s.subspec "SubPod-2" do |ss|
ss.public_header_files = "Classes/*.h"
ss.source_files = "Classes/SubPod-2/*.{h,m}"
end
end
Thanks for any help.
Your subspecs cannot depend on the parent spec, but can depend on other subspecs. You probably want to create some sort of "Core" subspec, then have SubPod 1 and 2 depend on that.

Unable to load SWF from application storage directory

While publishing my AIR application(CurrentFile), I have also included chatFile.swf with the installation files.
In my AIR settings panel [AIR 3.7 for Desktop], under 'Include Files' I have the following:
CurrentFile.swf
CurrentFile-app.xml
chatFile.swf
Here is the AS3 code in my CurrentFile.swf:
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Loader;
import flash.filesystem.File;
var chatLoaderWindow:Loader;
function loadchat(m:MouseEvent):void
{
chatLoaderWindow = new Loader();
chatLoaderWindow.contentLoaderInfo.addEventListener(Event.COMPLETE, chatLoadComplete);
chatLoaderWindow.contentLoaderInfo.addEventListener(Event.INIT, chatInitLoad);
chatLoaderWindow.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, chatErrorLoad);
chatLoaderWindow.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, chatHttpStatus);
myclip.chatwindow.addChild(chatLoaderWindow);
var f:File = File.applicationStorageDirectory.resolvePath("chatFile.swf");
chatLoaderWindow.load(new URLRequest(f.url));
tracebox.text = "Chat URL" + f.url;
}
function chatLoadComplete(e:Event):void
{
tracebox.text = "chat loaded";
}
function chatErrorLoad(io:IOErrorEvent):void
{
tracebox.text = "chat IO Error: "+io;
}
function chatInitLoad(i:Event):void
{
tracebox.text = "chat INIT";
}
function chatHttpStatus(e:HTTPStatusEvent):void
{
tracebox.text = "chat Http"+e;
}
myclip.chatbut.addEventListener(MouseEvent.CLICK,loadchat);
/*
Output:
chat IO Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2035" errorID=2035]
EDIT: I figured it out. It was really simple
This is not required:
var f:File = File.applicationStorageDirectory.resolvePath("chatFile.swf");
chatLoaderWindow.load(new URLRequest(f.url));
Insert this:
chatLoaderWindow.load(new URLRequest("app:/chatFile.swf"));
So now my question is:
What is the purpose of File.applicationStorageDirectory.resolvePath?
There are two directories here. One is the "application" directory, where your install files are placed. One is the "application-storage" directory, which is a convenient place to write files to at runtime. To access these directories you can either use the File.resolvePath() function or use the URI-scheme shortcuts, app: or app-storage:. In your initial attempt, you were just looking in the wrong directory for your file.
File.applicationStorageDirectory.resolvePath("somefile.swf").url will equal "app-storage:/somefile.swf"
File.applicationDirectory.resolvePath("somefile.swf").url will equal "app:/somefile.swf"
The application directory is where your app was installed. The app storage directory is a folder your app can save files to.
resolvePath() returns a file object. You can use it for purposes other than getting the cross-platform url for the file location, such as fileObj.exists and fileObj.parent.createDirectory(). fileObj.url is just the url you would use with URLLoader to access the file in a platform-independent manner.

How can I specify a different config file for testing in Play 2.1

I would like to define different database connections for multiple test environments(Production, Staging, Development). After reading the post "How do I specify a config file with sbt 0.12.2 for sbt test?" it seems that it was possible in earlier versions of Play, by using the follwing SBT setting:
val main = play.Project(appName, appVersion, appDependencies).settings(
javaOptions in Test += "-Dconfig.file=conf/test.conf"
)
But if I use this setting in my Build.scala, I get the following error:
not found: value javaOptions
So my question is, how can I define different connections for different test environments?
Edit:
A possible workaround would be to override the default setting during testing. This can be done with a environment variable.
object Config {
var defaultConfig = Map(
"db.default.user" -> "user",
"db.default.pass" -> "************"
)
def additionalConfiguration(): Map[String, _] = sys.env.getOrElse("PLAY_TEST_SCOPE", "") match {
case "development" => {
defaultConfig += "db.default.url" -> "jdbc:mysql://host:3306/development"
defaultConfig
}
case "staging" => {
defaultConfig += "db.default.url" -> "jdbc:mysql://host:3306/staging"
defaultConfig
}
case "production" => {
defaultConfig += "db.default.url" -> "jdbc:mysql://host:3306/production"
defaultConfig
}
case _ => {
throw new Exception("Environment variable `PLAY_TEST_SCOPE` isn't defined")
}
}
}
And then running a fake application with this configuration.
FakeApplication(additionalConfiguration = Config.additionalConfiguration())
javaOptions is contained within the Keys object.
Make sure that you use the proper import in your Build.scala file:
import Keys._
we can mix the above solutions, to pass the config file as a parameter to sbt.
This will be useful to integrate the test in CI pipeline
First, in the Build.scala file
val testOptions = "-Dconfig.file=conf/" + Option(System.getProperty("test.config")).getOrElse("application") + ".conf"
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
javaOptions in Test += testOptions
)
Then, in the command line to run the test with integ.conf
sbt -Dtest.config=integ test
to use the default application.conf
sbt test
Update for Play 2.5.x
Explicit import for import Keys._ is no longer required, and the vm param for config resource location has changed.
javaOptions in Test += "-Dconfig.resource=<conf_name>.conf"
You can run your application from console with alternative config file, anyway you need to use -Dconfig.file with full path as there are some problems ... that I can't realize with other option. For an example in unix env:
play -Dconfig.file=/home/akkie/play/some-project/conf/local_akkie_dev.conf "~run 9123"
Of course for easier launching you can create bash script for calling this line.
Edit: Note that you don't need to write whole config in each additional config file, as you can just include your main config at beginning and then overwrite only required properties :
include "application.conf"
key.to.override=blah
Take a look to the official doc

Own CocoaPods Pod Core Data file can't be accessed

I created my own CocoaPods Pod to use for my apps internally. This Pod should also use Core Data. I added my file xy.xcdatamodeld to my source files but it's not compiled into a xy.momd folder.
Do I need to set any other properties in my Pod to get Core Data to work?
My current pod file:
Pod::Spec.new do |s|
s.name = "Test"
s.version = "1.0"
s.summary = "..."
s.homepage = "..."
s.license = 'MIT (example)'
s.author = { "Felix Krause" => "xy#xy.com" }
s.source = { :git => "http://EXAMPLE/Example.podspec.git", :tag => "0.0.1" }
s.platform = :ios, '6.0'
s.source_files = 'TS/Classes/**/*.{h,m}', 'TS/Views/**/*.{h,m}', 'TS/TSResources/**/*.{json,xcdatamodeld}'
s.resources = "TS/TSResources/**/*"
s.frameworks = 'CoreData', 'QuartzCore', 'Accounts', 'MessageUI', 'CoreLocation', 'CoreGraphics', 'MobileCoreServices', 'SystemConfiguration'
s.requires_arc = true
s.ios.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(PODS_ROOT)/../../TS/**' }
s.ios.xcconfig ={ 'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/../.." "$(PODS_ROOT)/.." "$(SRCROOT)/.."' }
s.xcconfig = { 'OTHER_LDFLAGS' => '-all_load' }
s.dependency 'JSONKit'
end
Just so I can come back to this, it is actually supported. All you need to do is ensure that your pod spec lists the .xcdatamodeld under resources. Something to the effect of:
Pod::Spec.new do |s|
s.name = "MyPod"
s.version = "0.1"
s.platform = :ios, '8.0'
s.requires_arc = true
s.public_header_files = 'Pod/Classes/**/*.h'
s.source_files = 'Pod/Classes/**/*{h,m}'
s.resources = 'Pod/Classes/CoreData/*.xcdatamodeld'
s.frameworks = 'CoreData'
end
There is currently no explicit support for this. Here is an example of how you could do it. Note, however, that that code was untested, but it should be something along those lines. That specific user moved the model definition into code, in the end, btw.
HTH
Take a look at the following:
https://github.com/CocoaPods/Xcodeproj/issues/81#issuecomment-23142404
https://github.com/Ashton-W/CoreDataPodSample
I'm not very good at Ruby, so I don't understand alloy's example. What I do is just make sure that the xcdatamodeld is included as a source file, then make a reference in my project to that source file in the Pods directory.
The path ends up looking something like '../Pods/[PathToMyPod]/[MyDataModel].xcdatamodeld'.
Its a bit of a hack, but it gets the job done easily.