private BaiduMap mBaiduMap = null;
private MapView mMapView = null;
private LocationClient mLocClient = null;
private MyLocationConfiguration.LocationMode mCurrentMode;
private Boolean isFirstLoc = true;
private BitmapDescriptor mCurrentMarker=null;
private float[] accelerometerValues=new float[3];
private float[] magneticFieldValues=new float[3];
private float[] values=new float[3];
private float[] rotate=new float[9];
private float[] degree=new float[3];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
SensorManager sm = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
SensorEventListener sensorEventListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
accelerometerValues=event.values;
}
if(event.sensor.getType()==Sensor.TYPE_MAGNETIC_FIELD){
magneticFieldValues=event.values;
}
else
{
return;
}
SensorManager.getRotationMatrix(rotate, null, accelerometerValues, magneticFieldValues);
SensorManager.getOrientation(rotate, values);
//rotate
degree[0] = values[0]/3.1415926f*180;
//up down
degree[1] = values[1]/3.1415926f*180;
//left right
degree[2] = values[2]/3.1415926f*180;
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
sm.registerListener(sensorEventListener,sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_NORMAL);
sm.registerListener(sensorEventListener,sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),SensorManager.SENSOR_DELAY_NORMAL);
// init baiduMap
mMapView = (MapView) findViewById(R.id.dbmapView);
mBaiduMap = mMapView.getMap();
// set parameters
mCurrentMode = MyLocationConfiguration.LocationMode.FOLLOWING;
mCurrentMarker=null;
mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker));
// allow loaction
mBaiduMap.setMyLocationEnabled(true);
mLocClient = new LocationClient(this);
mLocClient.registerLocationListener(new MyLocationListenner());
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);
option.setCoorType("bd09ll");
option.setScanSpan(1000);
mLocClient.setLocOption(option);
mLocClient.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
public class MyLocationListenner implements BDLocationListener {
@Override
public void onReceiveLocation(BDLocation location) {
if (location == null || mMapView == null)
return;
MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
.direction(degree[0])
.latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
mBaiduMap.setMyLocationData(locData);
if (isFirstLoc) {
isFirstLoc = false;
LatLng ll = new LatLng(location.getLatitude(),
location.getLongitude());
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
mBaiduMap.animateMapStatus(u);
}
}
}
Category Archives: Language
Apple In House 发布详解(七牛升级服务器搭建)
大家都懂的,很多云存储比如Dropbox国内根本访问不了,某度的规则又不适合做这个功能。
那就用七牛吧。
1、到七牛注册账号
http://www.qiniu.com/
2、上传身份证,进行认证
谁让你想省钱呢
3、认证通过后,新建一个空间,设置开通HTTPS,设置自己的域名
假设你的访问地址为https://dn-xxxxxx.qbox.me/
4、将html文件及plist中文件的绝对路径全部修改为https://dn-xxxxxx.qbox.me/xxxxxx
5、上传文件,将plist的mime type修改为text/xml
6、搞定
还是花钱买的证书好用啊。
Apple In House 发布详解(HTTPS证书生成)
1、如果是在Windows下面,用openssl就可以搞定了
1.1首先生成pem格式的CA证书,并导出为crt格式
set OPENSSL_CONF=%OPENSSL_HOME%\bin\openssl.cfg openssl genrsa 1024 > NMyCA1024.key openssl req -new -x509 -nodes -key NMyCA1024.key -days 1095 -subj "/C=CN/ST=ShangHai/L=ShangHai/O=NEOHOPE/OU=Development/CN=NMyCA1024" > NMyCA1024.pem
1.2将CA证书导出为der格式
openssl x509 -outform der -in NMyCA1024.pem -out NMyCA1024.der
1.3生成网站私钥及证书签名请求
set OPENSSL_CONF=%OPENSSL_HOME%\bin\openssl.cfg openssl genrsa 1024 > server.key openssl req -new -key server.key -subj "/C=CN/ST=ShangHai/L=ShangHai/O=NEOHOPE/OU=Development/CN=192.168.130.50" > server.csr
1.4用CA证书处理证书签名请求,生成CA授权的证书
openssl x509 -req -in server.csr -CA NMyCA1024.pem -CAkey NMyCA1024.key -CAcreateserial -days 365 > serversigned.crt
1.5将NMyCA1024.der、server.key、serversigned.crt拷给证书使用者
1.6一定要保管好NMyCA1024.key及NMyCA1024.pem,不要弄丢,更不要拷给别人
2、如果是在MAC下面,有一个工具就能搞定EasyCert
./EasyCert -cn NMyCA -h 192.168.130.50
但同样的,要保护好CA的私钥。
Apple In House 发布详解(内网升级服务器搭建)
要内网升级的话,需要搭建内网升级HTTPS服务器。
以APACHE为例:
1、下载支持SSL的APACHE服务程序,如果你已经有APACHE服务,可以查找mod_ssl.so,如果没有请重新下载
2、打开HTTPS支持,httpd.conf文件中,去掉下面两行的注释
LoadModule ssl_module modules/mod_ssl.so Include conf/extra/httpd-ssl.conf
修改httpd-ssl.conf中证书信息
SSLCertificateFile "C:/ProgramerTools/WebServer/Apache2.2/conf/server.crt" SSLCertificateKeyFile "C:/ProgramerTools/WebServer/Apache2.2/conf/server.key"
3、将httpd.conf及httpd-ssl.conf路径信息调整为正确路径
4、此时HTTP与HTTPS都可以访问APACHE服务了
5、构建升级网站
5.1、准备资源文件
57×57图标,512×512图标,in house发布签名的ipa文件,CA根证书
5.2、准备plist文件
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- array of downloads. -->
<key>items</key>
<array>
<dict>
<!-- an array of assets to download -->
<key>assets</key>
<array>
<!-- software-package: the ipa to install. -->
<dict>
<!-- required. the asset kind. -->
<key>kind</key>
<string>software-package</string>
<!-- required. the URL of the file to download. -->
<key>url</key>
<string>https://192.168.130.50/XXXXX.ipa</string>
</dict>
<!-- display-image: the 57*57 icon to display during download. -->
<dict>
<key>kind</key>
<string>display-image</string>
<key>url</key>
<string>https://192.168.130.50/XXXXX_57.png</string>
</dict>
<!-- full-size-image: the large 512x512 icon used by iTunes. -->
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>url</key>
<string>https://192.168.130.50/XXXXX_512.png</string>
</dict>
</array>
<key>metadata</key>
<dict>
<!-- required -->
<key>bundle-identifier</key>
<string>程序的app id</string>
<!-- optional (software only) -->
<key>bundle-version</key>
<string>程序的版本</string>
<!-- required. the download kind. -->
<key>kind</key>
<string>software</string>
<!-- optional. displayed during download; -->
<!-- typically company name -->
<key>subtitle</key>
<string>厂商名称</string>
<!-- required. the title to display during the download. -->
<key>title</key>
<string>软件名称</string>
</dict>
</dict>
</array>
</dict>
</plist>
5.3、准备.htaccess文件,与plist文件放在一起
AddType text/xml .plist AddType application/octet-stream .ipa
修改httpd.conf文件,让.htaccess文件生效
#升级文件所在的目录 AllowOverride FileInfo
5.4、准备网页
<html>
<body>
<a href="https://192.168.130.46/myCA.cer">Install CA Cert</a>
</br>
<a href="itms-services://?action=download-manifest&url=https://192.168.130.50/XXXXX.plist">Install My App over the air </a>
</body>
</html>
6、使用
6.1、HTTPS访问网页,下载CA证书,并添加到IOS的信任列表
6.2、点击安装App,然后就开始自动安装啦
7、自动升级
请Google或github一下iVersion
Apple In House 发布详解(准备工作)
1、你需要知道自己为什么需要Apple In House发布应用,好处及限制分别是什么,不清楚请Google。
2、如果是公司申请,需要有D.U.N.S.编码(邓氏编码)
如果不嫌麻烦,可以国外申请
http://www.dunsregistered.com/
如果不差钱,请国内申请
http://dnbregistered.com.cn/
这个编码在做国际贸易的时候也很有用的
3、注册Apple Id,并购买iOS Development Enterprise Program,一定要搞清楚,不要买成iOS Development Program
4、使用发布版的Certificates和正确的App ID得到In House版本的Provisioning Profiles,其流程与普通发布证书一样,不清楚请Google
5、XCode使用正确的签名,编译并打包为ipa文件
6、将ipa拖到iTunes中,尝试用iTunes安装到你的IOS设备,如果安装不成功,请检查签名是否正确
XCode不显示AppleWatch模拟器
今天调试iWatch程序的时候,开始无论如何都没有iWatch模拟器。
后来发现,在IOS模拟器的菜单中,进行如下操作即可:
Hardware->External Displays->Apple Watch-38mm
或
Hardware->External Displays->Apple Watch-42mm
再次调试程序,目标选择WatchKit App就可以正常运行啦。
MAC解析HTML
- (void)fetchOneHtmlwithUrl:(NSURL *)url withCode:(NSString *)code withValueIn:(double)valueIn withMoneyIn:(double)moneyIn
{
NSError *error;
NSData *dataGB2312 = [[NSData alloc] initWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:&error];
NSStringEncoding gb2312Encoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString *htmlGB2312 = [[NSString alloc] initWithData:dataGB2312 encoding:gb2312Encoding];
NSString *utf8HtmlStr = [htmlGB2312 stringByReplacingOccurrencesOfString:@"charset=gb2312"
withString:@"charset=utf-8"];
NSData *dataUTF8 = [utf8HtmlStr dataUsingEncoding:NSUTF8StringEncoding];
ParseResultBean *bean = [ParseResultBean alloc];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:dataUTF8];
NSArray *eArrayCode = [xpathParser searchWithXPathQuery:@"/html/body/div[1]/div[7]/div[2]/div[1]/div[1]/div[1]/span[2]"];
TFHppleElement *eCode = [eArrayCode objectAtIndex:0];
bean->code = [[eCode attributes] objectForKey:@"title"];
[allRows addObject:bean];
}
MAC解析JSON
NSError *parseError;
NSData *jsonData = [sJsonText dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:&parseError];
if (json == nil)
{
NSLog(@"json parse failed. \r\n");
//NSLog([[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
NSLog(@"%@",[parseError localizedDescription]);
return;
}
NSArray *jijinArray = [json objectForKey:@"jijinlist"];
for(NSDictionary *jijin in jijinArray)
{
NSString *sCode = [jijin objectForKey:@"code"];
NSString *sValuein = [jijin objectForKey:@"valuein"];
}
MAC系统托盘图标
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGFloat f = 30.0;
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:f];
[statusItem setHighlightMode:YES];
[statusItem setTitle:[NSString stringWithFormat:@"%@",@"Hi"]];
[statusItem setMenu:statusMenu];
[statusItem setEnabled:YES];
}
CSharp程序设置自动启动
using System;
using System.Text;
using Microsoft.Win32;
namespace GPJJ
{
class XWin32Utils
{
private const String KEY_PATH = "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN";
private const String VALUE_NAME = "GPJJEXE";
public static bool isAutoRun()
{
RegistryKey key = Registry.LocalMachine;
RegistryKey autorun = key.OpenSubKey(KEY_PATH, true);
Object o = autorun.GetValue(VALUE_NAME);
autorun.Close();
if(o==null)
{
return false;
}
else
{
return true;
}
}
public static void SetAutoRun(String exePath)
{
RegistryKey key = Registry.LocalMachine;
RegistryKey autorun = key.OpenSubKey(KEY_PATH, true);
autorun.SetValue(VALUE_NAME, exePath, RegistryValueKind.String);
}
public static void RemoveAutoRun()
{
if(isAutoRun())
{
RegistryKey key = Registry.LocalMachine;
RegistryKey autorun = key.OpenSubKey(KEY_PATH, true);
autorun.DeleteValue(VALUE_NAME);
}
}
}
}