最近借到一隻 iphone 3G 來玩玩
結果沒辦法在執行在Device上
情怳是~編譯後在 title 上出現 finished running "程式" on ”裝置名稱”,
滿心期待的等了30秒後~確一直沒有出現在裝置上
重覆試了幾次結果也是一樣
只好上網google了
最後找到一篇討論~~ link
解法一:
Project -> Clean then Project -> Run again
解法二:
修改 architectures armv7 => armv6
而且我遇到的看來因該是要解法二了,
因為這專案新創的、因該沒有做到個設定
設定方法
OK~~終於出現在 iphone 3G 上面了
2011年11月8日 星期二
2011年10月12日 星期三
(iOS)如何新增AdMob (圖文教學)
前言:免費的應用程式記得設計區塊給廣告用來增加收入吧
1. get admob acount 申請admob申號
2.get publish id
(1)點選新增網站/應用程式
(2)choice iPhone / iPad 跟樣式
(3) get publish id 發佈商ID.
3. download SDK
Google AdMob Ads SDK for iOS
4. get code
You can download an
example project
or see see Google AdMob Ads iOS Fundamentals to code
5.define MY_BANNKER_UINT_ID as your AdMob Publish ID
6. build
PS:第一次執行是看不到廣告的 ,要等至少2分鐘才會接收成功
7not wait to test 不想等可以這麼做
find
replace
so you can see
最後不負責任預測~不久之後也許會改~因為目前AdMob被Google買下不久而已目前因該整合中
1. get admob acount 申請admob申號
2.get publish id
(1)點選新增網站/應用程式
(2)choice iPhone / iPad 跟樣式
(3) get publish id 發佈商ID.
3. download SDK
Google AdMob Ads SDK for iOS
4. get code
You can download an
example project
or see see Google AdMob Ads iOS Fundamentals to code
5.define MY_BANNKER_UINT_ID as your AdMob Publish ID
6. build
PS:第一次執行是看不到廣告的 ,要等至少2分鐘才會接收成功
7not wait to test 不想等可以這麼做
find
[bannerView_ loadRequest:[GADRequest request]];
replace
[GADRequest *testRequest = [GADRequest request];
testRequest.testing = YES;
[bannerView_ loadRequest:testRequest];
so you can see
最後不負責任預測~不久之後也許會改~因為目前AdMob被Google買下不久而已目前因該整合中
2011年10月4日 星期二
In App Purchase 交易通用機制
最近開始研究In App Purchase
以下教學都寫的很好
In App Purchase 學習筆記 (1)
In App Purchase 學習筆記 (2)In App Purchase 學習筆記 (3)
其中交易通用機制 ~用成中文圖解來記錄希望對大家有所幫助1. 內置產品類型
2. 服務器類型
2011年9月1日 星期四
read write plist 存讀取plist
//讀檔
//================================================================
//存檔
//================================================================
注意事項
1.未存過的檔案的第一次建構
2.檔案的路徑
- (void)readPlist
{
//取得檔案路徑
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/data.plist"];
//
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableDictionary *plistDict;
if ([fileManager fileExistsAtPath: filePath]) //檢查檔案是否存在
{
plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
}else{
plistDict = [[NSMutableDictionary alloc] init];
}
NSString *value;
value = [plistDict objectForKey:@"version"];
[plistDict release];
}
//================================================================
//存檔
//存檔
- (void)writePlist
{
//取得檔案路徑
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/data.plist"];
//
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableDictionary *plistDict;
if ([fileManager fileExistsAtPath: filePath]) //檢查檔案是否存在
{
plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
}else{
plistDict = [[NSMutableDictionary alloc] init];
}
[plistDict setValue:@"1.0.0" forKey:@"version"];
//存檔
if ([plistDict writeToFile:filePath atomically: YES]) {
NSLog(@"writePlist success");
} else {
NSLog(@"writePlist fail");
}
[plistDict release];
}
//================================================================
注意事項
1.未存過的檔案的第一次建構
2.檔案的路徑
標籤:
iOS,
objective-c,
XCode
2011年8月30日 星期二
UIDevice detect the specific model ~識別設備機型
#import <sys/utsname.h>
NSString*
machineName()
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
結果:
@"i386" on the simulator (我的出現x86_64)
@"iPod1,1" on iPod Touch
@"iPhone1,1" on iPhone
@"iPhone1,2" on iPhone 3G
@"iPhone2,1" on iPhone 3GS
@"iPad1,1" on iPad
@"iPhone3,1" on iPhone 4.
@"iPad2,1" on iPad2
標籤:
iOS,
objective-c,
XCode
UIRequiredDeviceCapabilities 指定程序需要那些設備
Key | 說明 | ||
telephony(電話) | Include this key if your application requires (or specifically prohibits) the presence of the Phone application. You might require this feature if your application opens URLs with the tel scheme | ||
wifi | Include this key if your application requires (or specifically prohibits) access to the networking features of the device. | ||
sms | Include this key if your application requires (or specifically prohibits) the presence of the Messages application. You might require this feature if your application opens URLs with the sms scheme. | ||
still-camera | Include this key if your application requires (or specifically prohibits) the presence of a camera on the device. Applications use the UIImagePickerController interface to capture images from the device’s still camera. | ||
auto-focus-camera | Include this key if your application requires (or specifically prohibits) auto-focus capabilities in the device’s still camera. Although most developers should not need to include this key, you might include it if your application supports macro photography or requires sharper images in order to do some sort of image processing. | ||
front-facing-camera | Include this key if your application requires (or specifically prohibits) the presence of a forward-facing camera. Applications use the UIImagePickerController interface to capture video from the device’s camera. | ||
camera-flash(相機閃光燈) | Include this key if your application requires (or specifically prohibits) the presence of a camera flash for taking pictures or shooting video. Applications use the UIImagePickerController interface to control the enabling of this feature. | ||
video-camera | Include this key if your application requires (or specifically prohibits) the presence of a camera with video capabilities on the device. Applications use the UIImagePickerController interface to capture video from the device’s camera. | ||
accelerometer(加速度計) | Include this key if your application requires (or specifically prohibits) the presence of accelerometers on the device. Applications use the classes of the Core Motion framework to receive accelerometer events. You do not need to include this key if your application detects only device orientation changes. | ||
gyroscope(陀螺儀) | Include this key if your application requires (or specifically prohibits) the presence of a gyroscope on the device. Applications use the Core Motion framework to retrieve information from gyroscope hardware. | ||
location-services(定位服務) | Include this key if your application requires (or specifically prohibits) the ability to retrieve the device’s current location using the Core Location framework. (This key refers to the general location services feature. If you specifically need GPS-level accuracy, you should also include the gps key.) | ||
gps | Include this key if your application requires (or specifically prohibits) the presence of GPS (or AGPS) hardware for greater accuracy when tracking locations. If you include this key, you should also include the location-services key. You should require GPS only if your application needs more accurate location data than the cell or Wi-fi radios might otherwise allow. | ||
magnetometer(磁力儀) | Include this key if your application requires (or specifically prohibits) the presence of magnetometer hardware. Applications use this hardware to receive heading-related events through the Core Location framework. | ||
microphone | Include this key if your application uses the built-in microphone or supports accessories that provide a microphone. | ||
opengles-1 | Include this key if your application requires (or specifically prohibits) the presence of the OpenGL ES 1.1 interfaces. | ||
opengles-2 | Include this key if your application requires (or specifically prohibits) the presence of the OpenGL ES 2.0 interfaces. | ||
armv6 | Include this key if your application is compiled only for the armv6 instruction set. (iOS v3.1 and later.) | ||
armv7 | Include this key if your application is compiled only for the armv7 instruction set. (iOS v3.1 and later.) | ||
peer-peer | Include this key if your application requires (or specifically prohibits) peer-to-peer connectivity over Bluetooth. (iOS v3.1 and later.) | ||
2011年8月23日 星期二
This generally means that another instance of this process was already running or is hung in the debugger
今天在測式時 crash之後
再編譯時就一直出現Error
再編譯時就一直出現Error
This generally means that another instance of this process was already running or is hung in the debugger
實體機上沒有看到在跑任何程式丫~
但就是重編不了~
最後是裝置關機重開才行~
2011年8月22日 星期一
iOS設備內存硬體
設備 | CPU | 螢幕顯示 | 內存 | ||
1代 | 412MHz | 480X320 | 128MB | ||
iPhone3G | 412MHz | 480X320 | 128MB | ||
iPod Touch | 532MHz | 480X320 | 128MB | ||
iPhone3GS | 600MHz | 480X320 | 256MB | ||
iPad | 1GHz | 1024X768 | 256MB | ||
iPhone4 | 1GHz | 960X640 | 512MB | ||
ipad2 | 1GHz 雙核心 Apple A5 | 1024X768 | 512MB | ||
如果要寫iphone程式,最好以128MB內存來思考,而且還要扣iOS系統佔用的
除非放棄iPhone3G、iPod Touch ~
而iPad程式呢~就要以256MB來思考,沒錯~iPad1的畫面比較大
,但可用就的內存就是比iPhone4來的少~~~~冏~~
2011年8月8日 星期一
真機調試 Received memory warning. Level= …
OSMemoryNotification.h
How the levels are triggered is not documented. SpringBoard is configured to do the following in each memory level:
1.Warning (not-normal) — Relaunch, or delay auto relaunch of nonessential background apps e.g. Mail.
2.Urgent — Quit all background apps, e.g. Safari and iPod.
3.Critical and beyond — The kernel will take over, probably killing SpringBoard or even reboot.
4.Killing the active app (jetsam) is not handled by SpringBoard, but launchd.
參考文章
在cocos2d呢
1 .Received memory warning. Level= 1
會觸發 [[CCDirector sharedDirector] purgeCachedData];
此時會把目前沒用到的 材質釋放掉~~
~
理論上ios系統會把不必要的背景程式關掉~
遇到這個情形呢~ 先查查leak吧
如果都沒有~就就就就…砍需求or改需求or改code~~~
減少在同一畫面下的內存使用量了
2 .Received memory warning. Level= 2
目前遇到的都crash 掉了~
還是乖乖查leak …
其他的還沒遇過~哈
typedef enum {
OSMemoryNotificationLevelAny = -1,
OSMemoryNotificationLevelNormal = 0,
OSMemoryNotificationLevelWarning = 1,
OSMemoryNotificationLevelUrgent = 2,
OSMemoryNotificationLevelCritical = 3
} OSMemoryNotificationLevel;
How the levels are triggered is not documented. SpringBoard is configured to do the following in each memory level:
1.Warning (not-normal) — Relaunch, or delay auto relaunch of nonessential background apps e.g. Mail.
2.Urgent — Quit all background apps, e.g. Safari and iPod.
3.Critical and beyond — The kernel will take over, probably killing SpringBoard or even reboot.
4.Killing the active app (jetsam) is not handled by SpringBoard, but launchd.
參考文章
在cocos2d呢
1 .Received memory warning. Level= 1
會觸發 [[CCDirector sharedDirector] purgeCachedData];
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
[[CCDirector sharedDirector] purgeCachedData];
}
此時會把目前沒用到的 材質釋放掉~~
~
理論上ios系統會把不必要的背景程式關掉~
遇到這個情形呢~ 先查查leak吧
如果都沒有~就就就就…砍需求or改需求or改code~~~
減少在同一畫面下的內存使用量了
2 .Received memory warning. Level= 2
目前遇到的都crash 掉了~
還是乖乖查leak …
其他的還沒遇過~哈
2011年7月31日 星期日
內存管理筆記
retainCount 是 objective-c 內存管理的唯一依據. release 後自動 retainCount 減 1 , 到 0 時 對象 的dealloc 會被觸發。
所以永遠不該呼叫 對象的 dealloc 方法
1,alloc, allocWithZone,new(帶初始化)
為對象分配內存,retainCount為“1”,並返回此實例
2,release
retainCount 減“1”,減到“0”時調用此對象的dealloc方法
3,retain
retainCount 加“1”
4,copy,mutableCopy
複製一個實例,retainCount數為“1”,返回此實例。所得到的對像是與其它上下文無關的,獨立的對象(乾淨對象)。
5,autorelease
在當前上下文的AutoreleasePool棧頂的autoreleasePool實例添加此對象,由於它的引入使Objective-C(非GC管理環境)由全手動內存管理上升到半自動化。
為對象分配內存,retainCount為“1”,並返回此實例
2,release
retainCount 減“1”,減到“0”時調用此對象的dealloc方法
3,retain
retainCount 加“1”
4,copy,mutableCopy
複製一個實例,retainCount數為“1”,返回此實例。所得到的對像是與其它上下文無關的,獨立的對象(乾淨對象)。
5,autorelease
在當前上下文的AutoreleasePool棧頂的autoreleasePool實例添加此對象,由於它的引入使Objective-C(非GC管理環境)由全手動內存管理上升到半自動化。
詳細參考文章:參考文章
2011年7月7日 星期四
CCLayer CCFadeOut unrecognized selector sent to instance !!~~~~
//目前使用的是 cocos2d 2.0 rc2 版
//
//在CCLayer 淡出效果時
[self runAction:[CCFadeOut actionWithDuration:0.8f]];
//會出現
[classXX setOpacity:]: unrecognized selector sent to instance 0xXXXXXXX !!
似呼有被回呼某 selector
所以必順實做 setOpacity 讓他變更
//
//在CCLayer 淡出效果時
[self runAction:[CCFadeOut actionWithDuration:0.8f]];
//會出現
[classXX setOpacity:]: unrecognized selector sent to instance 0xXXXXXXX !!
似呼有被回呼某 selector
所以必順實做 setOpacity 讓他變更
// Set the opacity of all of our children that support it
-(void) setOpacity: (GLubyte) opacity
{
for( CCNode *node in [self children] )
{
if( [node conformsToProtocol:@protocol( CCRGBAProtocol)] )
{
[(id) node setOpacity: opacity];
}
}
}
2011年7月5日 星期二
限定只有某CCLayer 觸發 touch
網路上片斷 +試驗
原理還沒詳細研究~先記錄囉~
原理還沒詳細研究~先記錄囉~
//================================================================
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES];
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
2011年6月30日 星期四
NSMutableArray sort NSString , NSNumber
//內容都是nsstring的
//
output:
2011-07-02 11:38:29.906 testCode[449:207] **************************************************
2011-07-02 11:38:29.907 testCode[449:207] ------------- original:
2011-07-02 11:38:29.908 testCode[449:207] arrData:A4
2011-07-02 11:38:29.908 testCode[449:207] arrData:A2
2011-07-02 11:38:29.908 testCode[449:207] arrData:a2
2011-07-02 11:38:29.909 testCode[449:207] arrData:A2
2011-07-02 11:38:29.909 testCode[449:207] arrData:A1
2011-07-02 11:38:29.910 testCode[449:207] ------------- sorted:
2011-07-02 11:38:29.910 testCode[449:207] sortedData:A1
2011-07-02 11:38:29.911 testCode[449:207] sortedData:A2
2011-07-02 11:38:29.911 testCode[449:207] sortedData:a2
2011-07-02 11:38:29.911 testCode[449:207] sortedData:A2
2011-07-02 11:38:29.911 testCode[449:207] sortedData:A4
2011-07-02 11:38:29.912 testCode[449:207] ------------- sorted:
2011-07-02 11:38:29.914 testCode[449:207] sortedData2:A1
2011-07-02 11:38:29.914 testCode[449:207] sortedData2:a2
2011-07-02 11:38:29.915 testCode[449:207] sortedData2:A2
2011-07-02 11:38:29.915 testCode[449:207] sortedData2:A2
2011-07-02 11:38:29.915 testCode[449:207] sortedData2:A4
//內容都是NSNumber的
output:
2011-07-02 11:38:29.915 testCode[449:207] **************************************************
2011-07-02 11:38:29.929 testCode[449:207] ------------- original:
2011-07-02 11:38:29.929 testCode[449:207] arrNum:5
2011-07-02 11:38:29.930 testCode[449:207] arrNum:1
2011-07-02 11:38:29.930 testCode[449:207] arrNum:3
2011-07-02 11:38:29.930 testCode[449:207] arrNum:2
2011-07-02 11:38:29.931 testCode[449:207] ------------- sorted:
2011-07-02 11:38:29.931 testCode[449:207] sortedNum:1
2011-07-02 11:38:29.931 testCode[449:207] sortedNum:2
2011-07-02 11:38:29.931 testCode[449:207] sortedNum:3
2011-07-02 11:38:29.932 testCode[449:207] sortedNum:5
//
NSLog(@"**************************************************");
//內容都是nsstring的
NSMutableArray *arrData = [NSMutableArray new];
[arrData addObject:@"A4"];
[arrData addObject:@"A2"];
[arrData addObject:@"a2"];
[arrData addObject:@"A2"];
[arrData addObject:@"A1"];
NSLog(@"------------- original:");
for (id obj in arrData) NSLog(@"arrData:%@", obj);
NSLog(@"------------- sorted:");
NSArray * sortedData =
[arrData sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
for (id obj in sortedData) NSLog(@"sortedData:%@", obj);
NSLog(@"------------- sorted:");
NSArray * sortedData2 =
[arrData sortedArrayUsingSelector:@selector(localizedCompare:)];
for (id obj in sortedData2) NSLog(@"sortedData2:%@", obj);
output:
2011-07-02 11:38:29.906 testCode[449:207] **************************************************
2011-07-02 11:38:29.907 testCode[449:207] ------------- original:
2011-07-02 11:38:29.908 testCode[449:207] arrData:A4
2011-07-02 11:38:29.908 testCode[449:207] arrData:A2
2011-07-02 11:38:29.908 testCode[449:207] arrData:a2
2011-07-02 11:38:29.909 testCode[449:207] arrData:A2
2011-07-02 11:38:29.909 testCode[449:207] arrData:A1
2011-07-02 11:38:29.910 testCode[449:207] ------------- sorted:
2011-07-02 11:38:29.910 testCode[449:207] sortedData:A1
2011-07-02 11:38:29.911 testCode[449:207] sortedData:A2
2011-07-02 11:38:29.911 testCode[449:207] sortedData:a2
2011-07-02 11:38:29.911 testCode[449:207] sortedData:A2
2011-07-02 11:38:29.911 testCode[449:207] sortedData:A4
2011-07-02 11:38:29.912 testCode[449:207] ------------- sorted:
2011-07-02 11:38:29.914 testCode[449:207] sortedData2:A1
2011-07-02 11:38:29.914 testCode[449:207] sortedData2:a2
2011-07-02 11:38:29.915 testCode[449:207] sortedData2:A2
2011-07-02 11:38:29.915 testCode[449:207] sortedData2:A2
2011-07-02 11:38:29.915 testCode[449:207] sortedData2:A4
//內容都是NSNumber的
NSLog(@"**************************************************");
//內容都是NSNumber的
NSMutableArray *arrNum = [NSMutableArray new];
[arrNum addObject:[[NSNumber alloc] initWithInt:5]];
[arrNum addObject:[[NSNumber alloc] initWithInt:1]];
[arrNum addObject:[[NSNumber alloc] initWithInt:3]];
[arrNum addObject:[[NSNumber alloc] initWithInt:2]];
NSLog(@"------------- original:");
for (id obj in arrNum) NSLog(@"arrNum:%@", obj);
NSLog(@"------------- sorted:");
NSArray * sortedNum = [arrNum sortedArrayUsingSelector:@selector(compare:)];
for (id obj in sortedNum) NSLog(@"sortedNum:%@", obj);
output:
2011-07-02 11:38:29.915 testCode[449:207] **************************************************
2011-07-02 11:38:29.929 testCode[449:207] ------------- original:
2011-07-02 11:38:29.929 testCode[449:207] arrNum:5
2011-07-02 11:38:29.930 testCode[449:207] arrNum:1
2011-07-02 11:38:29.930 testCode[449:207] arrNum:3
2011-07-02 11:38:29.930 testCode[449:207] arrNum:2
2011-07-02 11:38:29.931 testCode[449:207] ------------- sorted:
2011-07-02 11:38:29.931 testCode[449:207] sortedNum:1
2011-07-02 11:38:29.931 testCode[449:207] sortedNum:2
2011-07-02 11:38:29.931 testCode[449:207] sortedNum:3
2011-07-02 11:38:29.932 testCode[449:207] sortedNum:5
Cocos2d: 取得 CCSprite 寬跟高
//取得 CCSprite 寬跟高
CCSprite *sp = [CCSprite spriteWithFile:@"Icon.png"];
NSLog(@"sp width:%f,heigt,:%f",sp.contentSize.width , sp.contentSize.height);
2011年6月26日 星期日
用 NSMutableArray 記錄與取得 int ,CGPoint
Objective-C 真是一個麻煩的語言
//int 記錄與取得
myArray = [NSMutableArray array];
[myArray addObject:[NSNumber numberWithInteger:1234]];
//..
int theNumber = [[myArray objectAtIndex:0] integerValue];
//CGPoint記錄與取得
NSArray *points = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(5.5, 6.6)],
[NSValue valueWithCGPoint:CGPointMake(7.7, 8.8)], nil];
NSValue *val = [points objectAtIndex:0];
CGPoint p = [val CGPointValue];
訂閱:
文章 (Atom)