2017-12-28 00:51:14 kuangdacaikuang 阅读数 448

1. 本地通知 iOS10.0

本地通知 iOS10.0demo下载链接

iOS8.0 本地推送通知和接收通知及其跳转控制总结

1.1. 发送推送通知

//
//  ViewController.m
//  iOS10.0本地推送通知
//
//  Created by zhouyu on 2017/12/28.
//  Copyright © 2017年 zhouyu. All rights reserved.
//

#import "ViewController.h"
#import <UserNotifications/UserNotifications.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"ios10.0之后本地通知";
    [self setUpUI];
}


//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    // 使用 UNUserNotificationCenter 来管理通知
//    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
//
//    //需创建一个包含待通知内容的 UNMutableNotificationContent 对象,注意不是 UNNotificationContent ,此对象为不可变对象。
//    UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
//    content.title = [NSString localizedUserNotificationStringForKey:@"本地推送Title" arguments:nil];
//    content.body = [NSString localizedUserNotificationStringForKey:@"本地推送Body" arguments:nil];
//    content.sound = [UNNotificationSound defaultSound];
//
//    // 在 设定时间 后推送本地推送
//    UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger
//                                                  triggerWithTimeInterval:5 repeats:NO];
//
//    UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond"
//                                                                          content:content trigger:trigger];
//
//    //添加推送成功后的处理!
//    [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
//        NSLog(@"推送成功了");
//    }];
//}

- (void)setUpUI{
    UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 150, 60)];
    [btn1 setTitle:@"跳转红色控制器" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(red) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];

    UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(100, 400, 150, 60)];
    [btn2 setTitle:@"跳转蓝色控制器" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(blue) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
}

- (void)red{
    [self pushUNUserNotificationCenterWithRequestIdentifier:@"red" contentTitle:@"红色控制器" contentBody:@"跳转到红色控制器"];
}

- (void)blue{
    [self pushUNUserNotificationCenterWithRequestIdentifier:@"blue" contentTitle:@"蓝色控制器" contentBody:@"跳转到蓝色控制器"];
}

- (void)pushUNUserNotificationCenterWithRequestIdentifier:(NSString *)identifier contentTitle:(NSString *)title contentBody:(NSString *)body{
    // 使用 UNUserNotificationCenter 来管理通知
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];

    //需创建一个包含待通知内容的 UNMutableNotificationContent 对象,注意不是 UNNotificationContent ,此对象为不可变对象。
    UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
    content.title = [NSString localizedUserNotificationStringForKey:title arguments:nil];
    content.body = [NSString localizedUserNotificationStringForKey:body arguments:nil];
    content.sound = [UNNotificationSound defaultSound];

    // 在 设定时间 后推送本地推送
    UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger
                                                  triggerWithTimeInterval:5 repeats:NO];

    UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:identifier
                                                                          content:content trigger:trigger];

    //添加推送成功后的处理!
    [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
        NSLog(@"推送成功了");
    }];
}

@end

1.2. 注册和接收推送通知,并进行逻辑处理

//
//  AppDelegate.m
//  iOS10.0本地推送通知
//
//  Created by zhouyu on 2017/12/28.
//  Copyright © 2017年 zhouyu. All rights reserved.
//

#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>
#import "ViewController.h"
#import "RedController.h"
#import "BlueController.h"

@interface AppDelegate ()<UNUserNotificationCenterDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
    [self.window makeKeyAndVisible];
    self.window.backgroundColor = [UIColor whiteColor];

    // 使用 UNUserNotificationCenter 来管理通知
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    //监听回调事件
    center.delegate = self;

    //iOS 10 使用以下方法注册,才能得到授权
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
                              NSLog(@"error = %@",error);
                          }];

    return YES;
}

/*
 typedef NS_OPTIONS(NSUInteger, UNNotificationPresentationOptions) {
     UNNotificationPresentationOptionBadge   = (1 << 0),
     UNNotificationPresentationOptionSound   = (1 << 1),
     UNNotificationPresentationOptionAlert   = (1 << 2),
 }
 */
//当应用在前台的时候,收到本地通知,是用什么方式来展现。系统给了三种形式:
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    NSLog(@"%@",notification.request);

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@"APP在前台" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
    [alert show];

    // 处理完成后条用 completionHandler ,用于指示在前台显示通知的形式
    completionHandler(UNNotificationPresentationOptionSound);
}

//在后台或者程序被杀死的时候,点击通知栏调用的,在前台的时候不会被调用
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler{
    NSLog(@"%@",response);
//    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@"APP在后台或者被杀死后唤醒至前台" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
//    [alert show];

    [self jumpToControllerWithUNNotificationResponse:response];

    completionHandler();
}

//判断跳转
- (void)jumpToControllerWithUNNotificationResponse:(UNNotificationResponse *)response{
    UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
    if ([response.notification.request.identifier isEqualToString:@"red"]) {
        [nav pushViewController:[[RedController alloc] init] animated:YES];
    } else {
        [nav pushViewController:[[BlueController alloc] init] animated:YES];
    }
}


@end

这里写图片描述

这里写图片描述

这里写图片描述

2016-01-05 15:55:12 u011439689 阅读数 9163

一. 跳转到“设置”

//>=iOS8.0可用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

二. 跳转到设置的其它位置

1. 首先针对Info.plist添加如下选项


2. 调用跳转代码,如下

//跳转到“About”(关于本机)页面
NSURL *url = [NSURL URLWithString:@"prefs:root=General&path=About"];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}else{
NSLog(@"can not open");
}

三. 附,“设置”中各个页面的“地址”

About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI
Setting —prefs:root=INTERNET_TETHERING

注:手头只有iOS9.0的iPhone5s设备,测试可用

2015-11-17 14:38:16 u010843544 阅读数 838

//第一步判断用户是非开启授权访问相册

ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];

if (author == kCLAuthorizationStatusRestricted || author==kCLAuthorizationStatusDenied)

{ //无权限

.........

//没有授权的情况下,判断设备版本是否为8.0以上,是的可以对系统弹出的提示页面进行设置,添加一个“前往设置”的按钮,,,


     if (IOS_VERSION >= 8.0) {


//跳转到设置

        if (UIApplicationOpenSettingsURLString != NULL) {

            NSURL *appSettings = [NSURL                                                                              URLWithString:UIApplicationOpenSettingsURLString];

            [[UIApplication sharedApplication] openURL:appSettings];

        }

    }


}




2015-03-04 11:04:11 showhilllee 阅读数 18756

大家都知道,在iOS5.0时时可以跳转到系统的设置页的。但是在5.1之后就不可以了。

刚才研究了下这个问题,发现只有iOS8可以跳转到系统设置里自己App的页面。

目前没有找到iOS7怎么跳转过去。如果你知道请一定要留言告知,Thanks!

下面说下iOS8是如何跳转的,以下是代码:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
   [[UIApplication sharedApplication] openURL:url];
}

如果有感兴趣的同学可以留言大家谈论。

原文地址:http://blog.csdn.net/showhilllee/article/details/44057403

===================2015-07-22补充========================

跳转到系统WiFi设置页面代码:

NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];
[[UIApplication sharedApplication] openURL:url];

另附其他设置页面:

About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI
Setting —prefs:root=INTERNET_TETHERING

原文地址:http://blog.csdn.net/showhilllee/article/details/44057403


-----------警告⚠️------------

经过试验,在LZ的设备上跳转都没有问题(设备iPhone6,iOS8.3),但是在iphone5s,iphopn6 plus(都是8.4)上是无法跳转的。感觉苹果在走一条不归路啊~

PS.有其他手机或系统的可以留言下是否可以。


2018-05-21 16:46:03 github_36843038 阅读数 981

更新: iOS 11评价跳转
评价跳转一直是很多APP增添用户评价的快捷入口.在很多应用的设置,或者弹框中会出现给APP在Apple Store上进行评价,在网上找了很多个跳转的方法,发现以下可行:

说明:项目中的版本是iOS8.0
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id= 1195751596
<备注>
1195751596为你需要设置的你自己的APPID

因此,在项目中的可以进行以下操作

1.宏定义

#define APP_ID @""
// iOS 11 以下的评价跳转
#define APP_OPEN_EVALUATE [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", APP_ID]
// iOS 11 的评价跳转
#define APP_OPEN_EVALUATE_AFTER_IOS11 [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8&action=write-review", APP_ID]

2.调用跳转

在响应事件中,调用UIApplication的OpenURL的方法:
因为评价的存在iOS 11的分水岭,这里采用宏编译的方式

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_OPEN_EVALUATE_AFTER_IOS11]];
#else
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_OPEN_EVALUATE]];
#endif

OK,搞定

没有更多推荐了,返回首页