-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Mars iOS/OS X 接入指南
所有的编译脚本都在libraries目录
python build_apple.py
编译成功后,输出文件详细介绍如下:
文件名 | 描述 |
---|---|
mars.framework | mars framework |
log_crypt.cc.rewriteme |
</div>
<div class="HeaderMenu d-flex flex-justify-between flex-auto">
<div class="d-flex">
<div class="">
<div class="header-search scoped-search site-scoped-search js-site-search" role="search">
<label class="form-control header-search-wrapper js-chromeless-input-container">
<a href="/Tencent/mars/wiki/Mars-iOS%EF%BC%8FOS-X-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97/_edit" class="header-search-scope no-underline">This repository</a>
<input type="text" class="form-control header-search-input js-site-search-focus js-site-search-field is-clearable" data-hotkey="s" name="q" value="" placeholder="Search" aria-label="Search this repository" data-unscoped-placeholder="Search GitHub" data-scoped-placeholder="Search" autocapitalize="off">
<input type="hidden" class="js-site-search-type-field" name="type">
</label>
</div>
<ul class="d-flex pl-2 flex-items-center text-bold list-style-none" role="navigation">
<li>
<a href="/pulls" aria-label="Pull requests you created" class="js-selected-navigation-item HeaderNavlink px-2" data-ga-click="Header, click, Nav menu - item:pulls context:user" data-hotkey="g p" data-selected-links="/pulls /pulls/assigned /pulls/mentioned /pulls">
Pull requests
<div class="d-flex">
-
<a href="/notifications" aria-label="You have unread notifications" class="notification-indicator tooltipped tooltipped-s js-socket-channel js-notification-indicator" data-channel="notification-changed:8778898" data-ga-click="Header, go to notifications, icon:unread" data-hotkey="g n"> <span class="mail-status unread"></span> <svg aria-hidden="true" class="octicon octicon-bell" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M14 12v1H0v-1l.73-.58c.77-.77.81-2.55 1.19-4.42C2.69 3.23 6 2 6 2c0-.55.45-1 1-1s1 .45 1 1c0 0 3.39 1.23 4.16 5 .38 1.88.42 3.66 1.19 4.42l.66.58H14zm-7 4c1.11 0 2-.89 2-2H5c0 1.11.89 2 2 2z"></path></svg>
-
New repository Import repository New gist New organization
<div class="dropdown-menu-content js-menu-content"> <ul class="dropdown-menu dropdown-menu-sw">
This repositoryNew issue</ul> </div>
-
<details class="dropdown-details d-flex pl-2 flex-items-center"> <summary class="HeaderNavlink name" aria-label="View profile and more" data-ga-click="Header, show menu, icon:avatar"> <img alt="@garryyan" class="avatar" src="https://avatars0.githubusercontent.com/u/8778898?v=4&s=40" height="20" width="20"> <span class="dropdown-caret"></span> </summary> <ul class="dropdown-menu dropdown-menu-sw"> <li class="dropdown-header header-nav-current-user css-truncate"> Signed in as <strong class="css-truncate-target">garryyan</strong> </li> <li class="dropdown-divider"></li> <li><a class="dropdown-item" href="/garryyan" data-ga-click="Header, go to profile, text:your profile"> Your profile </a></li> <li><a class="dropdown-item" href="/garryyan?tab=stars" data-ga-click="Header, go to starred repos, text:your stars"> Your stars </a></li> <li><a class="dropdown-item" href="https://gist.github.com/" data-ga-click="Header, your gists, text:your gists">Your Gists</a></li> <li class="dropdown-divider"></li> <li><a class="dropdown-item" href="https://help.github.com" data-ga-click="Header, go to help, text:help"> Help </a></li> <li><a class="dropdown-item" href="/settings/profile" data-ga-click="Header, go to settings, icon:settings"> Settings </a></li> <li><!-- '"` --><!-- </textarea></xmp> --><form accept-charset="UTF-8" action="/logout" class="logout-form" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="/YYufoTOzPOAnXidhez1k3L7JzvJ8qWHWZuVVw90M7LAjuo+MRW9T41GcatSBH5rrs65ebDE14rs/r8SR5+njQ=="></div> <button type="submit" class="dropdown-item dropdown-signout" data-ga-click="Header, sign out, icon:logout"> Sign out </button> </form></li> </ul> </details>
<!-- '"` --><!-- </textarea></xmp> --><form accept-charset="UTF-8" action="/logout" class="sr-only right-0" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="umysFf360XaU0IZD1BnJ8bxrA/d6cnnDPRkssxquES2HZGhVSCGgypkLj3UD8UIJYF6dtQNEC86IfAb2UkWFEg=="></div>
<button type="submit" class="dropdown-item dropdown-signout" data-ga-click="Header, sign out, icon:logout">
Sign out
</button>
<div id="js-flash-container">
<div class="pagehead repohead instapaper_ignore readability-menu experiment-repo-nav">
<div class="container repohead-details-container">
<ul class="pagehead-actions">
<div class="select-menu js-menu-container js-select-menu">
<a href="/Tencent/mars/subscription" class="btn btn-sm btn-with-count select-menu-button js-menu-target" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Toggle repository notifications menu" data-ga-click="Repository, click Watch settings, action:wiki#edit">
<span class="js-select-button">
<svg aria-hidden="true" class="octicon octicon-eye" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"></path></svg>
Unwatch
</span>
</a>
<a class="social-count js-social-count" href="/Tencent/mars/watchers" aria-label="633 users are watching this repository">
633
</a>
<div class="select-menu-modal-holder">
<div class="select-menu-modal subscription-menu-modal js-menu-content">
<div class="select-menu-header js-navigation-enable" tabindex="-1">
<svg aria-label="Close" class="octicon octicon-x js-menu-close" height="16" role="img" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path></svg>
<span class="select-menu-title">Notifications</span>
</div>
<div class="select-menu-list js-navigation-container" role="menu">
<div class="select-menu-item js-navigation-item " role="menuitem" tabindex="0">
<svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path></svg>
<div class="select-menu-item-text">
<input id="do_included" name="do" type="radio" value="included">
<span class="select-menu-item-heading">Not watching</span>
<span class="description">Be notified when participating or @mentioned.</span>
<span class="js-select-button-text hidden-select-button-text">
<svg aria-hidden="true" class="octicon octicon-eye" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"></path></svg>
Watch
</span>
</div>
</div>
<div class="select-menu-item js-navigation-item selected" role="menuitem" tabindex="0">
<svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path></svg>
<div class="select-menu-item-text">
<input checked="checked" id="do_subscribed" name="do" type="radio" value="subscribed">
<span class="select-menu-item-heading">Watching</span>
<span class="description">Be notified of all conversations.</span>
<span class="js-select-button-text hidden-select-button-text">
<svg aria-hidden="true" class="octicon octicon-eye" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"></path></svg>
Unwatch
</span>
</div>
</div>
<div class="select-menu-item js-navigation-item " role="menuitem" tabindex="0">
<svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path></svg>
<div class="select-menu-item-text">
<input id="do_ignore" name="do" type="radio" value="ignore">
<span class="select-menu-item-heading">Ignoring</span>
<span class="description">Never be notified.</span>
<span class="js-select-button-text hidden-select-button-text">
<svg aria-hidden="true" class="octicon octicon-mute" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8 2.81v10.38c0 .67-.81 1-1.28.53L3 10H1c-.55 0-1-.45-1-1V7c0-.55.45-1 1-1h2l3.72-3.72C7.19 1.81 8 2.14 8 2.81zm7.53 3.22l-1.06-1.06-1.97 1.97-1.97-1.97-1.06 1.06L11.44 8 9.47 9.97l1.06 1.06 1.97-1.97 1.97 1.97 1.06-1.06L13.56 8l1.97-1.97z"></path></svg>
Stop ignoring
</span>
</div>
</div>
</div>
</div>
</div>
</div>
<h1 class="public ">
</div>
<div class="container">
<span itemscope="" itemtype="http://schema.org/ListItem" itemprop="itemListElement">
<a href="/Tencent/mars/issues" class="js-selected-navigation-item reponav-item" data-hotkey="g i" data-selected-links="repo_issues repo_labels repo_milestones /Tencent/mars/issues" itemprop="url">
<svg aria-hidden="true" class="octicon octicon-issue-opened" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
<span itemprop="name">Issues</span>
<span class="Counter">24</span>
<meta itemprop="position" content="2">
Pull requests 0
<a href="/Tencent/mars/projects" class="js-selected-navigation-item reponav-item" data-selected-links="repo_projects new_repo_project repo_project /Tencent/mars/projects">
<svg aria-hidden="true" class="octicon octicon-project" height="16" version="1.1" viewBox="0 0 15 16" width="15"><path fill-rule="evenodd" d="M10 12h3V2h-3v10zm-4-2h3V2H6v8zm-4 4h3V2H2v12zm-1 1h13V1H1v14zM14 0H1a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h13a1 1 0 0 0 1-1V1a1 1 0 0 0-1-1z"></path></svg>
Projects
<span class="Counter">0</span>
</div>
</div>
<div id="gollum-editor-format-selector" class="gollum-editor-format-selector">
<label for="wiki_format">Edit mode:</label>
<select class="form-select select select-sm" id="wiki_format" name="wiki[format]"><option value="asciidoc">AsciiDoc</option>
To create a paragraph, simply create a block of text that is not separated by one or more blank lines. Blocks of text separated by one or more blank lines will be parsed as paragraphs.
If you want to create a line break, end a line with two or more spaces, then hit Return/Enter.
<textarea aria-label="Page content" class="form-control input-block gollum-editor-body comment-form-textarea js-comment-field js-quick-submit js-suggester-field input-with-fullscreen-icon" data-markup-lang="markdown" format="markdown" id="gollum-editor-body" name="wiki[body]" required="required">所有的编译脚本都在[libraries目录](https://github.com/Tencent/mars/tree/master/mars/libraries)
python build_apple.py
编译成功后,输出文件详细介绍如下:
文件名 | 描述 |
---|---|
mars.framework | mars framework |
log_crypt.cc.rewriteme | 日志可扩展部分,使用前先改名为 log_crypt.cc,如若想自己实现日志加密等逻辑,重写该文件。 |
log_crypt.h | 编译 log_crypt.cc 需要使用的头文件,请勿修改。 |
longlink_packer.cc.rewriteme | 长连接协议可扩展部分,使用前请先改名为 longlink_packer.cc,如若想自定义长连接包头以及加解包,重写该文件。 |
longlink_packer.h | 编译 longlink_packer.cc 需要使用的头文件,请勿修改。 |
stnproto_logic.h | longlink_packer.cc 中 SetClientVersion 函数的声明。如若删除 SetClientVersion 函数,请同时删除该文件。 |
shortlink_packer.cc.rewriteme | 短连接协议可扩展部分,使用前请先改名为 shortlink_packer.cc,如若想自定义短连接包头(HTTP Head),重写该文件。 |
shortlink_packer.h | 编译 shortlink_packer.cc 需要使用的头文件,请勿修改。 |
以下接入部分可参考 mars/samples/iOS 和 mars/samples/Mac。 强调:所有直接调用 C/C++接口的 Objc 源文件必须是 .mm 后缀,不能是.m 后缀。
其中红色部分为 mars 提供的部分,黄色部分是使用 mars 需要的系统库,绿色部分为需要开发者自行实现的 callback 部分。
推荐在 main.mm 的 main 函数里初始化:
NSString* logPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/log"];
// set do not backup for logpath
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
setxattr([logPath UTF8String], attrName, &attrValue, sizeof(attrValue), 0, 0);
// init xlog
#if DEBUG
xlogger_SetLevel(kLevelDebug);
appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
appender_open(kAppednerAsync, [logPath UTF8String], "Test", PUB_KEY);
在 applicationWillTerminate 函数中反初始化:
appender_close();
上面的步骤介绍了在iOS/OSX中如何在进程启动和退出时打开关闭xlog,下面还需要讲一下xlog的使用方法,我们可以看到上图中Component部分有
LogUtil.h
这是我们为objc开发者提供的上层应用封装,开发者可将Component中的代码全部复制到自己的代码中进行修改或直接使用,日志打印宏支持可变参数。
LOG_DEBUG(TAG, @"I wanna say: %@", @"hello mars!");
LOG_INFO(TAG, @"I wanna say: %@", @"hello mars!");
LOG_WARNING(TAG, @"I wanna say: %@", @"hello mars!");
LOG_ERROR(TAG, @"I wanna say: %@", @"hello mars!");
TAG请自行定义
需要注意:
- 保存 log 的目录请使用单独的目录,不要存放任何其他文件防止被 xlog 自动清理功能误删。
- 请把 log 目录设上不备份的标识。
- debug 版本下建议把控制台日志打开,日志级别设为 Debug, release 版本建议把控制台日志关闭,日志级别使用 Info.
建议在 didFinishLaunchingWithOptions 函数中或者使用网络之前进行初始化:
- (void)setCallBack {
mars::stn::SetCallback(mars::stn::StnCallBack::Instance());
mars::app::SetCallback(mars::app::AppCallBack::Instance());
}
- (void) createMars {
mars::baseevent::OnCreate();
}
- (void)setClientVersion:(UInt32)clientVersion {
mars::stn::SetClientVersion(clientVersion);
}
- (void)setShortLinkDebugIP:(NSString *)IP port:(const unsigned short)port {
std::string ipAddress([IP UTF8String]);
mars::stn::SetShortlinkSvrAddr(port, ipAddress);
}
- (void)setShortLinkPort:(const unsigned short)port {
mars::stn::SetShortlinkSvrAddr(port);
}
- (void)setLongLinkAddress:(NSString *)string port:(const unsigned short)port debugIP:(NSString *)IP {
std::string ipAddress([string UTF8String]);
std::string debugIP([IP UTF8String]);
std::vector<uint16_t> ports;
ports.push_back(port);
mars::stn::SetLonglinkSvrAddr(ipAddress,ports,debugIP);
}
- (void)setLongLinkAddress:(NSString *)string port:(const unsigned short)port {
std::string ipAddress([string UTF8String]);
std::vector<uint16_t> ports;
ports.push_back(port);
mars::stn::SetLonglinkSvrAddr(ipAddress,ports);
}
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForeground);
}
- (void)makesureLongLinkConnect {
mars::stn::MakesureLonglinkConnected();
}
初始化顺序不一定要严格遵守上述代码的顺序,但在初始化时首先要调用 setCallBack 接口(callback 文件的编写可以参考 demo ),最后再调用 onForeground 和 makesureLongLinkConnect,中间顺序可以随意更改。注意:STN 默认是后台,所以初始化 STN 后需要主动调用一次BaseEvent.onForeground(true)
在程序退出时或需要释放 stn 时调用:
- (void)destroyMars {
mars::baseevent::OnDestroy();
}
当发生前后台切换时调用:
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForeground);
}
发生网络切换时调用:
- (void)reportEvent_OnNetworkChange {
mars::baseevent::OnNetworkChange();
}
github/Mars 的默认分支为 master 分支,几个含义的含义分别是:
- master 分支;最近一次 release 的稳定代码,我们在 master 分支打 tag,所有 master 上的代码都应是经过微信全量验证过;
- dev 分支;开发分支,这里会包含下一个版本的代码,我们只能给 dev 分支提 pr 以及验证部分已经修复的 issue;
关于 Mars 分支管理、issue 以及 pr 规范,请阅读 Mars Contributing Guide。
选好一个需要调试的分支后,Mars 源码调试就很简单了,这里以 iOS 调试为例,OS X 几乎方式一样。在调试之前建议先按照上述步骤中的链接(因为编译的时候需要这一步的头文件)部分编译通过。文字描述如下:
- 移除 "Link Binary With Libraries" 中的 mars.framework
- 把 Mars 的项目文件 "mars-open-iphone.xcodeproj" 拖到项目中,以子项目的方式存在
- 把 "libmars-open-iphone.a" 添加到 "Link Binary With Libraries" 中
- 把 "mars-open-iphone" 添加到 "Target Dependencies" 中
- 加断点,编译调试
更详细的的接口说明请参考 Mars iOS/OS X 接口详细说明
</textarea><div class="suggester-container">
<div class="suggester js-suggester js-navigation-container" data-url="/suggestions/wiki?repository=mars&user_id=Tencent">
</div>
</div>
</div>
<a href="https://github.com" aria-label="Homepage" class="footer-octicon" title="GitHub">
<svg aria-hidden="true" class="octicon octicon-mark-github" height="24" version="1.1" viewBox="0 0 16 16" width="24"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>
</ul>
<script crossorigin="anonymous" integrity="sha256-cUJKZyfMSZTaV7iAZjGvC/jPf3foLPlxQS0Sgj1w3rs=" src="https://assets-cdn.github.com/assets/frameworks-71424a6727cc4994da57b8806631af0bf8cf7f77e82cf971412d12823d70debb.js"></script>
<script async="async" crossorigin="anonymous" integrity="sha256-d8diY11YePOZsScXOCmfjbPdkxVWb9T/+XBW4l8f21c=" src="https://assets-cdn.github.com/assets/github-77c762635d5878f399b1271738299f8db3dd9315566fd4fff97056e25f1fdb57.js"></script>
<script crossorigin="anonymous" integrity="sha256-JHPhLg1b/eNJYyI4TeyftiHlYiGuPDien2Z1vcRZOa4=" src="https://assets-cdn.github.com/assets/wiki-2473e12e0d5bfde3496322384dec9fb621e56221ae3c389e9f6675bdc45939ae.js"></script>
以下接入部分可参考 mars/samples/iOS 和 mars/samples/Mac。 强调:所有直接调用 C/C++接口的 Objc 源文件必须是 .mm 后缀,不能是.m 后缀。
其中红色部分为 mars 提供的部分,黄色部分是使用 mars 需要的系统库,绿色部分为需要开发者自行实现的 callback 部分。
推荐在 main.mm 的 main 函数里初始化:
NSString* logPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/log"];
// set do not backup for logpath
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
setxattr([logPath UTF8String], attrName, &attrValue, sizeof(attrValue), 0, 0);
// init xlog
#if DEBUG
xlogger_SetLevel(kLevelDebug);
appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
appender_open(kAppednerAsync, [logPath UTF8String], "Test", PUB_KEY);
在 applicationWillTerminate 函数中反初始化:
appender_close();
上面的步骤介绍了在iOS/OSX中如何在进程启动和退出时打开关闭xlog,下面还需要讲一下xlog的使用方法,我们可以看到上图中Component部分有
LogUtil.h
这是我们为objc开发者提供的上层应用封装,开发者可将Component中的代码全部复制到自己的代码中进行修改或直接使用,日志打印宏支持可变参数。
LOG_DEBUG(TAG, @"I wanna say: %@", @"hello mars!");
LOG_INFO(TAG, @"I wanna say: %@", @"hello mars!");
LOG_WARNING(TAG, @"I wanna say: %@", @"hello mars!");
LOG_ERROR(TAG, @"I wanna say: %@", @"hello mars!");
TAG请自行定义
需要注意:
- 保存 log 的目录请使用单独的目录,不要存放任何其他文件防止被 xlog 自动清理功能误删。
- 请把 log 目录设上不备份的标识。
- debug 版本下建议把控制台日志打开,日志级别设为 Debug, release 版本建议把控制台日志关闭,日志级别使用 Info.
建议在 didFinishLaunchingWithOptions 函数中或者使用网络之前进行初始化:
- (void)setCallBack {
mars::stn::SetCallback(mars::stn::StnCallBack::Instance());
mars::app::SetCallback(mars::app::AppCallBack::Instance());
}
- (void) createMars {
mars::baseevent::OnCreate();
}
- (void)setClientVersion:(UInt32)clientVersion {
mars::stn::SetClientVersion(clientVersion);
}
- (void)setShortLinkDebugIP:(NSString *)IP port:(const unsigned short)port {
std::string ipAddress([IP UTF8String]);
mars::stn::SetShortlinkSvrAddr(port, ipAddress);
}
- (void)setShortLinkPort:(const unsigned short)port {
mars::stn::SetShortlinkSvrAddr(port);
}
- (void)setLongLinkAddress:(NSString *)string port:(const unsigned short)port debugIP:(NSString *)IP {
std::string ipAddress([string UTF8String]);
std::string debugIP([IP UTF8String]);
std::vector<uint16_t> ports;
ports.push_back(port);
mars::stn::SetLonglinkSvrAddr(ipAddress,ports,debugIP);
}
- (void)setLongLinkAddress:(NSString *)string port:(const unsigned short)port {
std::string ipAddress([string UTF8String]);
std::vector<uint16_t> ports;
ports.push_back(port);
mars::stn::SetLonglinkSvrAddr(ipAddress,ports);
}
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForeground);
}
- (void)makesureLongLinkConnect {
mars::stn::MakesureLonglinkConnected();
}
初始化顺序不一定要严格遵守上述代码的顺序,但在初始化时首先要调用 setCallBack 接口(callback 文件的编写可以参考 demo ),最后再调用 onForeground 和 makesureLongLinkConnect,中间顺序可以随意更改。注意:STN 默认是后台,所以初始化 STN 后需要主动调用一次BaseEvent.onForeground(true)
在程序退出时或需要释放 stn 时调用:
- (void)destroyMars {
mars::baseevent::OnDestroy();
}
当发生前后台切换时调用:
- (void)reportEvent_OnForeground:(BOOL)isForeground {
mars::baseevent::OnForeground(isForeground);
}
发生网络切换时调用:
- (void)reportEvent_OnNetworkChange {
mars::baseevent::OnNetworkChange();
}
github/Mars 的默认分支为 master 分支,几个含义的含义分别是:
- master 分支;最近一次 release 的稳定代码,我们在 master 分支打 tag,所有 master 上的代码都应是经过微信全量验证过;
- dev 分支;开发分支,这里会包含下一个版本的代码,我们只能给 dev 分支提 pr 以及验证部分已经修复的 issue;
关于 Mars 分支管理、issue 以及 pr 规范,请阅读 Mars Contributing Guide。
选好一个需要调试的分支后,Mars 源码调试就很简单了,这里以 iOS 调试为例,OS X 几乎方式一样。在调试之前建议先按照上述步骤中的链接(因为编译的时候需要这一步的头文件)部分编译通过。文字描述如下:
- 移除 "Link Binary With Libraries" 中的 mars.framework
- 把 Mars 的项目文件 "mars-open-iphone.xcodeproj" 拖到项目中,以子项目的方式存在
- 把 "libmars-open-iphone.a" 添加到 "Link Binary With Libraries" 中
- 把 "mars-open-iphone" 添加到 "Target Dependencies" 中
- 加断点,编译调试
更详细的的接口说明请参考 Mars iOS/OS X 接口详细说明
Mars Android 接入指南
Mars iOS/OS X 接入指南
Mars Windows 接入指南
Xlog 加密使用指引
Mars 常用术语
Mars 常见问题
Mars 自定义扩展
Mars Sample 使用说明
Mars Android 接口详细说明
Mars iOS/OS X 接口详细说明
Mars 其他资料
STN Benchmark
Xlog Benchmark
微信 Mars — 移动互联网下的高质量网络连接探索(小蛮腰科技大会PPT)
微信终端跨平台组件 Mars 系列(一) - 高性能日志模块 xlog
微信终端跨平台组件 Mars 系列 (二) - 信令传输超时设计