如上一篇博文提到的,在BB10 Cascades使用过程中,有些时候会遇到开发环境的一些问题,这个时候如果能去查看BB10 Cascades自身的日志一般都会有一些线索。
那么,如何查看BB10 Cascades开发环境的日志呢?方法比较简单,找到你使用的workspace目录,比如我使用C:\\workspace\\bbndk作为我的“workspace”,那就打开C:\\workspace\\bbndk目录,在该目录中有一个.metadata目录,目录中有个.log文件,通过文本编辑器打开它就可以看到BB10 Cascades自身的日志了。
另外还有一个方便的方法,就是在BB10 Cascades环境中点击“Help -> report a bug”,这样就出来一个“问题提交”的页面,在该页面中选择“Attachment”标签页,里面就有上面提到的.log日志文件,双击可以直接在BB10 Cascades中打开它。
同时,如果你希望提交问题给RIM公司,还可以在“问题提交”的“Bug report”页面填写你遇到的问题,直接点击“Submit”就可以了,不过英文要好哟。
//
// httpsClass.h
// https
//
// Created by 夏 科杰 on 12-12-20.
// Copyright (c) 2012年 夏 科杰. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface httpsClass : NSObject
{
NSMutableURLRequest* _request;
NSURLConnection * connection;
NSStringEncoding enc;
NSURLAuthenticationChallenge *_challenge;
NSMutableData* muData;
bool isFinish;
}
-(NSString *)initWithUrl:(NSString* )url postData:(NSString* )data;
@end
//
// httpsClass.m
// https
//
// Created by 夏 科杰 on 12-12-20.
// Copyright (c) 2012年 夏 科杰. All rights reserved.
//
#import "httpsClass.h"
@implementation httpsClass
-(NSString *)initWithUrl:(NSString* )requestUrl postData:(NSString* )data
{
enc=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
_request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestUrl]];
NSData *aData = [data dataUsingEncoding: NSUTF8StringEncoding];
[_request setHTTPMethod: @"POST"];
[_request setHTTPBody:aData];
assert(_request != nil);
connection = [NSURLConnection connectionWithRequest:_request delegate:self];
[self _receiveDidStart];
if(connection)
{
muData = [[NSMutableData data] retain];
NSLog(@"intial done!");
}
else
{
NSLog(@"sorry");
}
isFinish=NO;
while(!isFinish) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
NSLog(@"%@",muData);
return [[NSString alloc] initWithData:muData encoding:NSUTF8StringEncoding];
}
#pragma mark - Tell the UI we are receiving or received.
- (void)_receiveDidStart
{
NSLog(@"receiving");
}
- (void)_receiveDidStopWithStatus:(NSString *)statusString
{
if (statusString == nil) {
NSLog(@"Get succeeded");
}else
NSLog(@"Get not succeeded");
// NSLog(@"---%@",statusString);
}
- (void)_stopReceiveWithStatus:(NSString *)statusString
{
if (connection != nil) {
[connection cancel];
connection = nil;
}
if (_challenge !=nil) {
[_challenge release];
}
[self _receiveDidStopWithStatus:statusString];
}
- (BOOL)connection:(NSURLConnection *)conn canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
NSLog(@"authenticate method:%@",protectionSpace.authenticationMethod);
return [protectionSpace.authenticationMethod isEqualToString:
NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)conn didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLog(@"%@",challenge);
_challenge=[challenge retain];
NSURLCredential * credential;
NSURLProtectionSpace * protectionSpace;
SecTrustRef trust;
NSString * host;
SecCertificateRef serverCert;
//三次握手
assert(_challenge !=nil);
protectionSpace = [_challenge protectionSpace];
assert(protectionSpace != nil);
trust = [protectionSpace serverTrust];
assert(trust != NULL);
credential = [NSURLCredential credentialForTrust:trust];
assert(credential != nil);
host = [[_challenge protectionSpace] host];
if (SecTrustGetCertificateCount(trust) > 0) {
serverCert = SecTrustGetCertificateAtIndex(trust, 0);
} else {
serverCert = NULL;
}
[[_challenge sender] useCredential:credential forAuthenticationChallenge:_challenge];
}
- (void)connection:(NSURLConnection *)conn didReceiveResponse:(NSURLResponse *)response
{
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse *) response;
assert( [httpResponse isKindOfClass:[NSHTTPURLResponse class]] );
if ((httpResponse.statusCode / 100) != 2) {
[self _stopReceiveWithStatus:[NSString stringWithFormat:@"HTTP error %zd", (ssize_t) httpResponse.statusCode]];
} else {
NSLog(@"status: ok");
}
//NSLog(@"%@",httpResponse);
NSLog(@"get the whole response");
[muData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"get some data");
[muData appendData:data];//返回数据
}
- (void)connection:(NSURLConnection *)conn didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError %@", error);
[self _stopReceiveWithStatus:@"Connection failed"];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)conn
{
#pragma unused(conn)
NSLog(@"connectionDidFinishLoading");
isFinish=YES;
[self _stopReceiveWithStatus:nil];
}
@end
http=[httpsClass new];
NSString *postPram = [NSString stringWithFormat:@"requestData={\"api_Channel\":\"3\",\"api_name\":\"api.news.find_article_weekly_daily_news_list\",\"params\":{\"type\":%d,\"pageNo\":%d,\"pageSize\":%d}}",1,1,10];
NSLog(@"%@",[http initWithUrl:@"https://**.**.**.**/api/x.htm" postData:postPram]);
在设计手机移动应用的时候,需要尽量利用手机有限的屏幕,为了不让按钮占用太多空间,我们可以使用菜单项替代按钮,将用户需要执行的操作集中到菜单上。
BB10 Cascades QML中可以为页面(page)添加“ActionItem”组件,“ActionItem”组件将出现在屏幕下方的操作条中,或者出现在菜单栏里,具体是出现在哪里由开发人员通过ActioniItem的ActionBar.placement属性来指定。
为了给页面添加ActionItem,需要在页面中添加actions属性,格式如下:
// Default empty project template import bb.cascades 1.0 // creates one page with a label Page { Container { //这里添加我们页面中需要的组件 } //这里开始action的定义 actions: [ ActionItem { //第一个item title: "Action 1" //item 的文字 ActionBar.placement: ActionBarPlacement.OnBar //item的摆放位置,缺省放在菜单了,加了这行就放屏幕下方的操作条里 onTriggered: { //点击触发的事件 myLabel.text = "Action 1 selected!" } }, ActionItem { //第二个item.... title: "Action 2" onTriggered: { myLabel.text = "Action 2 selected!" } } ] }
以上添加的菜单项(ActionItem)执行的操作是改变myLabel组件的文字,这里还是使用之前的"Hello World"样例为基础,所以myLabel指向“Hello World”标签。
所以以下语句将“Hello World”标签修改成“Action 1 selected!”:
myLabel.text="Action 1 selected!"
为页面添加菜单项后可以在QML预览界面看到菜单项的效果,虽然不能点击测试,不过可以预先查看菜单项的静态效果,见下图:
下面是应用进行测试时在模拟器上显示的效果,用户点击“Action1”可以将“Hello World”标签的文字修改为“Action 1 selected!”:
下面是用户点击操作条右方“更多..”按钮菜单的效果: