如何在两个自定义iOS框架中添加依赖项?

时间:2018-05-18 12:40:36

标签: frameworks dependencies cocoapods git-submodules ios-frameworks

我已经创建了自定义框架,可以在我当前的iOS应用程序中使用。

  • profileManager.Framework
  • messagemanager.Framework
  • requestManager.Framework

现在都是profileManager.Framework& messagemanager.Framework实际上是使用requestManager.Framework方法所以我想要的是在我的应用程序的Xcode项目中我只想保留requestManager.Framework代码的一个物理副本。我希望我的请求管理器代码应该只有一个副本每个应用程序和引用应该与其他框架链接。

我们已经在本地机器上创建了这个框架。现在我的问题是我们无法在profileManager.Framework中添加依赖项,或者在messagemanager.Framework中添加依赖项。我想知道我的两个框架如何能够使用应用程序中的网络管理器以及应用程序的单个副本。

2 个答案:

答案 0 :(得分:1)

在单一视图应用程序级别拥有该框架,并确保在App和Framework的构建设置中正确地给出框架路径。

通过这种方式,您只能在项目级别维护一个框架副本,并且可以在项目或项目框架级别中自由使用。

答案 1 :(得分:1)

如何尝试使用CocoaPods管理这些框架的依赖关系? 在UserManager.FrameworkInboxManager.Framework的podspec中,配置依赖项s.dependency 'NetworkManager', '~> 1.0'。这样,您的应用程序中只能有一个NetworkManager.framework代码的物理副本。

例如,AlamofireImageAlamofire-SwiftyJSON都依赖于Alamofire,但只有Alamofire.framework的一个物理副本在应用中安装pod install并运行public class MainActivity extends AppCompatActivity { private static final String TAG = "bluetooth"; private BluetoothAdapter bluetoothAdapter; private Button mBTEnableButton; private BroadcastReceiver mReceiver; private TextView mShowDevices; private ProgressBar mProgressBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mBTEnableButton = findViewById(R.id.enable_bt_button); mShowDevices = findViewById(R.id.show_connected_devices); mProgressBar = findViewById(R.id.progressbar); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mReceiver = new BlueToothReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED); intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); intentFilter.addAction(BluetoothDevice.ACTION_FOUND); registerReceiver(mReceiver, intentFilter); mProgressBar.setVisibility(View.INVISIBLE); if (bluetoothAdapter == null) { Toast.makeText(this, "Device does not support bluetooth", Toast.LENGTH_SHORT).show(); } mBTEnableButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!bluetoothAdapter.isEnabled()) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, 1000); bluetoothAdapter.startDiscovery(); } } }); } private class BlueToothReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d("bluetooth", "onReceive"); String action = intent.getAction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); String deviceName = device.getName(); String deviceAddress = device.getAddress(); mShowDevices.setText("action : " + action + "\n device name: " + deviceName + "\ndevice address : " + deviceAddress); Log.d("bluetooth", "action : " + action + "\n device name: " + deviceName + "\ndevice address : " + deviceAddress); } else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) { mProgressBar.setVisibility(View.VISIBLE); Log.d(TAG, "discovery start: "); } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { mProgressBar.setVisibility(View.INVISIBLE); Log.d(TAG, "discovery finish: "); } } } @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(mReceiver); }}

参考:AlamofireImage.podspecAlamofire-SwiftyJSON.podspec