The articles
Look for similar pictures in IOS photo albums with NSNotification and class objects, instance objects iCloud-Documents storage
Create a Spec index library
Create a remote index library
Create a library named MySpecs in git on the Intranet to save CocoaPods’ search path library on the Intranet.
Pod repo add DemoSpecs http://192.168.3.225:4080/mbackupper/mobile/MySpecs.gitCopy the code
Associate the remote index library to the local
Use the Pod command to associate the remote index library with the local
Touch readme.md git add readme.md git commit -m "private index library" git add remote http://192.168.3.225:4080/mbackupper/mobile/MySpecs.git git push -u origin masterCopy the code
This will be in the.cocoapods folder in the ~ directory on your PC. You can see that there are two folders under repos, one for master and one for MySpecs.
Master is the official index library for Cocoapods, while MySpecs is the private index library we just set up, so there’s nothing in it yet. This will store some private components of the Intranet, as shown in the following figure.
MySpecs stores indexes to the relevant private libraries, not the specific private libraries
The location where the private repository is actually stored
If the remote index library is not associated with the local library, the following error will be generated
Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.
Copy the code
Generate a private component library
Create a project using the Pod template
The generated remote library does not hold any private library indexes. Now let’s create a private component library and add it to the remote library.
Use the template to create an AMMediator project.
pod lib create AMMediator
Copy the code
The template will ask you a few questions about the creation
What language do you want to use?? [ Swift / ObjC ]
> objc
Would you like to include a demo application with your library? [ Yes / No ]
> yes
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> none
Would you like to do view based testing? [ Yes / No ]
> no
What is your class prefix?
> AM
Copy the code
For MacOS, create template projects in the default directory /Users/ MAC.
The directory structure is as follows
Example stores the demo
Ammediators mainly store code and required resources
The Podspec file records information about the current component, including git addresses, descriptions, dependencies, and so on
Put the source code into the template
In the AMMediator directory, Assets are used to save the resources related to component libraries, and Classes are used to save the source code related to component libraries
Then go to Example and execute
pod install
Copy the code
In Example, we have successfully imported the private component library. We can write some examples of using the private component library in Example.
Here we use the template to create a private component library.
Save the template to a remote library
Modify the ammediator. podspec configuration file in the template project, which is used for the indexing task of the index library, and the index library can find the actual location of the corresponding private library based on the Podspec file.
As you can see from the figure above, the index held in MySpecs is essentially a PodSpec configuration file for each private component library
The configuration structure of the PodSpecs is as follows
#
# Be sure to run `pod lib lint AMMediator.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'AMMediator'
s.version = '1.1.1'
s.summary = 'my module'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC TODO: Add long description of the pod here. DESC
s.homepage = 'https://xxxxxxx/AMMediator'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type= >'MIT'.:file= >'LICENSE' }
s.author = { 'coderjun'= >'[email protected]' }
s.source = { :git= >'http://192.168.3.225:4080/mbackupper/mobile/ios_modules/modulerepos/ammediator.git'.:tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '9.0'
s.source_files = 'AMMediator/Classes/**/*'
# s.resource_bundles = {
# 'AMMediator' => ['AMMediator/Assets/*.png']
#}
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.endency 'AFNetworking', '~> 2.3'
end
Copy the code
The key parameters
The actual location of the remote Git repository where the AMMeditor project is located
S.ource: tag: corresponds to the tag version number, as you can see here is the value in s. sion
S.source_files: where the private component source code is stored, in the aforementioned Classes directory.
S.dapendency: Third-party components that private components depend on, such as our private components depend on AFNetworking
S. sion: s. sion must be consistent with the tag in git in the private component library.
After modifying the PodSpec file, you can push the local private component library code to the remote library. Note that when tagging in your local Git library, it should match the version in your PodSpec. It is recommended that you write an SH with the bundlVersion in your private component project as the tag, and set the TAG in your PodSpec s.
This way we simply set up the bundleVersion in the project, and then use the script to package and upload. The script will automatically sync our bundleVersion to our PodSpec file and tag us in Git.
The author implements the following packaging script
# get bundlVersion
function cmd_push() {# get bundlVersion
BundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" /Users/mac/Desktop/Modules/MCiCloudDrivePlugin/MCiCloudDrivePlugin.framework/Info.plist)
# sed replaces the spec text content
sed -i "" "s/s.version\([ ]\{1,\}\)=\([ ]\{1,\}\)\([\'|\"]\)\([^\"]\{1,\}\([\'|\"]\)\)/s.version = \"$BundleVersion\"/g" MCiCloudDrivePlugin.podspec
# git update and tag
git add .
git commit -m "update $BundleVersion"
git push -u origin master
git tag $BundleVersion
git push --tags
Push to the local POD library and release the versionpod repo push AMModuleSpecs MCiCloudDrivePlugin.podspec --use-libraries --allow-warnings - sources = http://192.168.3.225:4080/mbackupper/mobile/ios_modules/ammodulespecs.gitecho "Script execution completed"
}
Copy the code
Finally, the private library is added to the private index library
pod repo push AMModuleSpecs AMMediator.podspec
Copy the code
When we’re done, we can see that our private library AMMediator has been added to the private index library.
We can access our own private source by simply setting the relevant source for the Podfile file in the project.
source 'https://gitee.com/mirrors/CocoaPods-Specs.git'
source 'http://192.168.3.225:4080/mbackupper/mobile/ios_modules/ammodulespecs.git'
platform :ios.'9.1'
use_frameworks!
target 'mBackup' do
pod 'AMMediator' ,'0.1.1'
end
Copy the code
CocoaPods private source in some high confidentiality of the project, you can achieve the Intranet to build some private component library for the project team to use, while avoiding the private component library can be external access to the problem.