2011年10月25日 星期二

開啟Mac OS的Root Admin

系統偏好設定>使用者與群組>>登入選項>按下網路帳號伺服"加入"按鈕>打開目錄工具程式>選Menu Bar的"編輯">啟用Root使用者>最後輸入Root使用者新的密碼就大功告成

P.S. 參考網址:http://www.thewwwblog.com/enable-root-user-in-mac-os-x-super-admin-access.html

2011年10月9日 星期日

iOS NSString to NSDate/NSDate to NSString

NSString to NSDate
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
// 把時間設定成世界時間
//[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate* date = [dateFormatter dateFromString:@"Date String"];
[dateFormatter release];

NSDate to NSString
NSDateFormatter* outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString* dateString = [outputFormatter stringFromDate:date];
[outputFormatter release];

2011年10月3日 星期一

iOS Local Notification

又是時候把學習了的總理一下,
再記錄下來了,
今次的是Local Notification

1.即時的 Local Notification
UIBackgroundTaskIdentifier bgTask;
- (void)applicationDidEnterBackground:(UIApplication *)application {
if(bgTask == UIBackgroundTaskInvalid)
{
UIApplication* app = [UIApplication sharedApplication];

// 開啟了BackgroundTask就要以令以下的queue在Background/Foreground Task都可以運行
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"System Expiration End Background Task");
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];

// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UILocalNotification* notification = [[UILocalNotification alloc] init];
notification.alertBody = @"Test";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
[notification release];

[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
}

2.Schedule Local Notification
UILocalNotification* notification = [[UILocalNotification alloc] init];
notification.alertBody = @"Test";
// 在當前時間10秒後發動
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
// Alert View 不會顯示 View button
notification.hasAction = FALSE;
notification.userInfo = [NSDictionary dictionaryWithObject:@"Key" forKey:@"Key"];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];

3.Cancel Local Notification
// 在 scheduled 的 Local Notification Array 找出要的 Local Notification Object
NSUInteger idx = [[UIApplication sharedApplication].scheduledLocalNotifications indexOfObjectPassingTest:
^(id obj, NSUInteger idx, BOOL *stop)
{
NSDictionary* userData = ((UILocalNotification*)obj).userInfo;
NSInteger key = [[userData valueForKey:@"Key"] integerValue];
if([key isEqualToString:@"Key"])
{
*stop = TRUE;
return YES;
}
return NO;
}];

if(idx != NSNotFound)
{
UILocalNotification* notification = [[UIApplication sharedApplication].scheduledLocalNotifications objectAtIndex:idx];
[[UIApplication sharedApplication] cancelLocalNotification:notification];
}