Category Archives: IOS

ios開発にプッシュ通知を実装する方法

1.Push通知
UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
NSDate *pushDate = [NSDate dateWithTimeIntervalSinceNow:15]; if (notification != nil) {
// push time
notification.fireDate = pushDate;
// set zone
notification.timeZone = [NSTimeZone defaultTimeZone];
// 時間間隔
notification.repeatInterval = kCFCalendarUnitDay;
// push sound
notification.soundName = UILocalNotificationDefaultSoundName;
// push content
notification.alertBody = @”arkgame.com provide it”; notification.applicationIconBadgeNumber = 1;
NSDictionary *info = [NSDictionary dictionaryWithObject:@”name”forKey:@”key”];
notification.userInfo = info;
//push add UIApplication
UIApplication *app = [UIApplication sharedApplication]; [app scheduleLocalNotification:notification];
}

2.プッシュ通知の取得
– (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”iWeibo” message:notification.alertBody delegate:nil cancelButtonTitle:@”ok” otherButtonTitles:nil];
[alert show];
application.applicationIconBadgeNumber -= 1;
}

3.プッシュ通知の解除
// UIApplicationの取得
UIApplication *app = [UIApplication sharedApplication];
//プッシュの配列を取得
NSArray *localArray = [app scheduledLocalNotifications];
//通知オブジェクトの宣言
UILocalNotification *localNotification;
if (localArray) {
for (UILocalNotification *noti in localArray) {
NSDictionary *dict = noti.userInfo;
if (dict) {
NSString *inKey = [dict objectForKey:@”key”];
if ([inKey isEqualToString:@”key value”]) {
if (localNotification){
[localNotification release];
localNotification = nil;
}
localNotification = [noti retain];
break;
}
}
}
//同じキーが既に存在するかどうか
if (!localNotification) {
localNotification = [[UILocalNotification alloc] init];
}
if (localNotification) {
//プッシュの解除
[app cancelLocalNotification:localNotification];
[localNotification release];
return;
}
}

「ios開発」ファイルを削除するサンプルコード

サンプルコード
NSFileManager *defaultManager;
defaultManager = [NSFileManager defaultManager];
[defaultManager removeFileAtPath: tildeFilenamehandler: nil]

「ios開発」plistファイルの読み込む方法

サンプルコード:
NSString *path = [[NSBundle mainBundle] pathForResource:@”filename_startnews24″ ofType:@”plist”];
// file data type array
NSArray *array=[NSArray arrayWithContentsOfFile:path];
//file data type *dictionary
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:path];

ASIHTTPRequestでhttpsにアクセスする方法

方法1
ASIHTTPRequest *request = [ASIHTTPRequestrequestWithURL:[NSURLURLWithString:bodyString]];

[request setDelegate:self];

request.timeOutSeconds = 20;

[request setRequestMethod:@”POST”];

[request addRequestHeader:@”Content-Type”value:@”application/xml;charset=UTF-8;”];

[request setValidatesSecureCertificate:NO];//httpsにアクセス

[request startAsynchronous];

方法2

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:bodyString]];
[request setDelegate:self];
request.timeOutSeconds = 20;
[request setValidatesSecureCertificate:NO];
[request setRequestMethod:@”POST”]; [request addRequestHeader:@”Content-Type” value:@”application/xml;charset=UTF-8″]; request.defaultResponseEncoding = NSUTF8StringEncoding;

「Objective-C」ios開発でNavigationBarを透明にする方法のまとめ

方法1
if ([self.navigationController.navigationBarrespondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
NSArray *list = self.navigationController.navigationBar.subviews;
for (id objin list) {
if ([obj isKindOfClass:[UIImageViewclass]]) {
UIImageView *imageView = (UIImageView *)obj;
imageView.hidden = YES;
}
}
}

方法2
[self.navigationController.navigationBar setShadowImage:[UIImage new]];

「Objective-C」ios開発でLableの長さによってimageViewの長さを伸びる方法

処理コード:
_reserveLabel.text = @”welcome to arkgame.com”;
//Labelのコンテンツ長さを取得
CGSize reserveLabelSize = [_reserveLabel sizeThatFits:CGSizeMake(MAXFLOAT, 32)];

//Lableのframeをリセット
_reserveLabel.frame = CGRectMake(10, 0, reserveLabelSize.width, 32);

//imageに背景画像を置く
UIImage *image = [UIImage imageNamed:@”biao1″];

//ストレッチ位置を選択
image = [image stretchableImageWithLeftCapWidth:(2) topCapHeight:(0)];

//imageViewのframeをリセット
_reserveImageView.frame = CGRectMake(0, cookImageViewH – 17 – 32, _reserveLabel.width + 20, 32);

//imageViewのimageを設定
_reserveImageView.image = image;

「Objective-C」ios開発でtextFieldの値変更をリアルタイムリスナーする方法

参考ソースコード:
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:
@selector(infoAction)name:UITextFieldTextDidChangeNotificationobject:nil];
– (void)infoAction
{
NSIndexPath *index = [NSIndexPathindexPathForRow:0inSection:1];
OrderConfirmInfoTableViewCell *cell = (OrderConfirmInfoTableViewCell *)[_tableViewcellForRowAtIndexPath:index];
_phoneStr = cell.phoneField.text;
_addrStr = cell.addressField.text;
}

「Objective-C」日付を操作する方法のまとめ

//現在の日付
NSDate *today = [NSDate date];

//タイムゾーン
NSTimeZone *zone = [NSTimeZone systemTimeZone];

//間隔を設定
_interval = [zone secondsFromGMTForDate: today];

//明日の日付を取得
NSDate *tomorrowDate = [[NSDate alloc]initWithTimeInterval:24 * 60 * 60 sinceDate:[NSDate date]];

//カレンダー
NSCalendar *calendar = [NSCalendar currentCalendar];

//年月日
NSDateComponents *comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit |NSWeekdayOrdinalCalendarUnit | NSHourCalendarUnit) fromDate:tomorrowDate];
//weekdayを取得
NSInteger weekday = [comps weekday];

//日時をNSStringからNSDateに変換
NSDate *serverDate = [dateFomatter dateFromString:serverTimeStr];
NSDate *createDate = [dateFomatter dateFromString:createTimeStr];

//二つDate時間の間隔
NSTimeInterval betweenTime = [serverDate timeIntervalSinceDate:createDate];

//年月日分秒
NSDateFormatter *dateFomatter = [[NSDateFormatter alloc]init];
[dateFomatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”];

//stringをformatterに変換
NSDate *stringDate = [dateFomatter dateFromString:string];
[dateFomatter setDateFormat:@”MM-dd”];

//文字列の月日を抽出
NSString *str1 = [dateFomatter stringFromDate:stringDate];

ios7にcontentsizeで高さを取得する方法

参考コード:
[cell.methodTextView.text boundingRectWithSize:CGSizeMake(cell.methodTextView.frame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:cell.methodTextView.font,NSFontAttributeName, nil] context:nil].size.height

説明:
textviewのtext文字列を呼び出してboundingRectWithSize方法を利用してCGpointを取得する
CGpointでsize.heightを取得

「ios開発」CCArrayの使い方を纏める

1.配列に要素を追加
CCSprite* pRet=CCSprite::create(“test.png”);
pArray->addObject(pRet);

2.要素を削除
pArray->removeObject(pRet);
pArray->removeObjectAtIndex(0);

3. foreachの使い方
CCObject* pObj;
//フォワード
CCARRAY_FOREACH(s_pBulletArray,pObj)
{
CMapNode* pNode=(CMapNode*)pObj;
}
//逆方向
CCARRAY_FOREACH_REVERSE(s_pBulletArray,pObj)
{
CMapNode* pNode=(CMapNode*)pObj;
}

4.forループ遍歴
for (unsigned int i = 0; i <s_pBulletArray->count(); ++i)
{
CCNode* pObj=(CCNode*)s_pBulletArray->objectAtIndex(i);
}

for (int i = arr->count()-1; i>=0 ; –i)

{
CMonster* pObj=(CMonster*)arr->objectAtIndex(i);
bool isCollide = false;
isCollide =rect.intersectsRect(pObj->getCollideRect());
if (isCollide)
{
arr->removeObject(pObj);
}
}