iOS 8 為 Notification Center 帶來新功能,所以取得 token 的 api 也修改了,如下所示:
if(IS_IOS8)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
2014年9月27日 星期六
2014年9月26日 星期五
[iOS] iOS 8 用 UIAlertController 來取代原本的 UIAlertView & UIActionSheet
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@“title" message:@“message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@“cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@“ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:cancelAction];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
以下連結有更詳細的介紹:
http://useyourloaf.com/blog/2014/09/05/uialertcontroller-changes-in-ios-8.html
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@“cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@“ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:cancelAction];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
以下連結有更詳細的介紹:
http://useyourloaf.com/blog/2014/09/05/uialertcontroller-changes-in-ios-8.html
[iOS] iOS 8 進入 Settings 復活了
原本在 iOS 5.0 支援的終於在 iOS 8 又回來了,但目前只能進入 "Settings" 而己...
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
[iOS] iOS 7&8 UISearchBar 去除背景的方法
UISearchBar 在 iOS 的不同版本中,把 subviews 列出來看會發現 view 層次結構不同,而要去除背景主要是將 UISearchBarBackground 給 remove 掉,因此就要針對各個 iOS 的版本做點調整,如下所示:
for (UIView *view in self.searchBar.subviews)
{
iOS 7 以前:
if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[view removeFromSuperview];
break;
}
iOS 7 含以後:
if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0)
{
for (UIView *subView in view.subviews)
{
if ([subView isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subView removeFromSuperview];
break;
}
}
}
}
for (UIView *view in self.searchBar.subviews)
{
iOS 7 以前:
if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[view removeFromSuperview];
break;
}
iOS 7 含以後:
if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0)
{
for (UIView *subView in view.subviews)
{
if ([subView isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subView removeFromSuperview];
break;
}
}
}
}
訂閱:
文章 (Atom)