-(NSString *) stringByStrippingHTML:(NSString *)s
{
NSRange r;
//NSString *s = [[self copy] autorelease];
while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
s = [s stringByReplacingCharactersInRange:r withString:@""];
s = [s stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
return s;
}
Reduced PDF file size in Mac OS
Open ColorSync Utility in the Utilities folder off of the Applications folder. ColorSync Utility can create new Quartz filters. Open up ColorSync Utility and switch to the “Filters” pane. This will list all of the filters that you currently have available.
- In the lower left, click on the “+” button. This creates a new filter.
- Give the filter a name, and press return.
- To the right of the filter’s name, choose the down arrow. A menu will pop up.
- From the pop-up menu, choose “Add Image Effects Component”, and from that menu choose “Image Compression”.
- Adjust the image compression Mode to JPEG.
- Adjust the image compression quality however you prefer.
- The next time you use Preview to “Save As...”, you'll have a new option under Quartz filters.
Get All Local Notification
UIApplication *app = [UIApplication sharedApplication];
NSArray *alarmArray = [app scheduledLocalNotifications];
for (int i=0; i<[alarmArray count]; i++)
{
UILocalNotification* oneAlarm = [alarmArray objectAtIndex:i];
NSDictionary *userInfoCurrent = oneAlarm.userInfo;
NSDate *dateCurrent = [userInfoCurrent valueForKey:@"date"];
NSNumber *typeCurrent = [userInfoCurrent valueForKey:@"type"];
NSLog(@"Found scheduled alarm with date:%@, type:%@", dateCurrent,typeCurrent );
}
Labels:
UILocalNotification
Cancel Local Notification
Cancel all local notifications with this code:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Cancel one local notification with this line of code:
[[UIApplication sharedApplication] cancelLocalNotification:theNotification];
Labels:
cancel,
delete,
remove,
UILocalNotification
Repeat Local Notification
NSInteger index = [scheduleControl selectedSegmentIndex];
switch (index) {
case 1:
notif.repeatInterval = NSMinuteCalendarUnit;
break;
case 2:
notif.repeatInterval = NSHourCalendarUnit;
break;
case 3:
notif.repeatInterval = NSDayCalendarUnit;
break;
case 4:
notif.repeatInterval = NSWeekCalendarUnit;
break;
default:
notif.repeatInterval = 0;
break;
}
- NSEraCalendarUnit
- NSYearCalendarUnit
- NSMonthCalendarUnit
- NSDayCalendarUnit
- NSHourCalendarUnit
- NSMinuteCalendarUnit
- NSSecondCalendarUnit
- NSWeekCalendarUnit
- NSWeekdayCalendarUnit
- NSWeekdayOrdinalCalendarUnit
- NSQuarterCalendarUnit
Labels:
interval,
repeat,
UILocalNotification
Handling Local Notifications After They Fire
In your app delegate .m file and add the following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Application was not running when notification was delivered.
Class cls = NSClassFromString(@"UILocalNotification");
if (cls) {
UILocalNotification *notification = [launchOptions objectForKey:
UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
NSString *reminderText = [notification.userInfo
objectForKey:kRemindMeNotificationDataKey];
[viewController showReminder:reminderText];
}
}
application.applicationIconBadgeNumber = 0;
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive)
{
// Application was in the background when notification was delivered.
}
else
{
// Application was in the foreground when notification was delivered.
}
}
Labels:
UILocalNotification
Schedule Local Notification
- (void) scheduleNotificationOn:(NSDate*) fireDate
text:(NSString*) alertText
action:(NSString*) alertAction
sound:(NSString*) soundfileName
launchImage:(NSString*) launchImage
andInfo:(NSDictionary*) userInfo
{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *raceDate = [df dateFromString: [df stringFromDate: fireDate]];
//localNotification.fireDate = fireDate;
localNotification.fireDate = raceDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = alertText;
localNotification.alertAction = alertAction;
if(soundfileName == nil)
{
localNotification.soundName = UILocalNotificationDefaultSoundName;
}
else
{
localNotification.soundName = soundfileName;
}
localNotification.alertLaunchImage = launchImage;
self.badgeCount ++;
localNotification.applicationIconBadgeNumber = self.badgeCount;
localNotification.userInfo = userInfo;
// Schedule it with the app
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
}
Labels:
UILocalNotification
Adding days to NSDate
int daysToAdd = 1;
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:daysToAdd];
// create a calendar
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *newDate = [gregorian dateByAddingComponents:components toDate:datePicker.date options:0];
Labels:
add,
date,
iphone SDK,
nsdate
Width of UILabel's Text
iPhone SDK Tips & Tricks
CGSize textSize = [[label text] sizeWithFont:[label font]];
CGFloat strikeWidth = textSize.width;
Labels:
iphone SDK,
uilabel
Subscribe to:
Posts (Atom)