【imessage苹果推】群发软件安装包含(Local Notification)

NSString *version = [[[NSBundle mainBundle]infoDictionary] objectForKey:@“CFBundleVersion”];

iOS 当地推送(Local Push) 推送是咱俩日常平凡开辟寻常用的一种体制,不管iOS仍是Android体系都有推送,推送能够让不在后台运转的app,奉告租户app个中产生的工作,可以进步app的翻开用户数,增添日活。 iOS中的推送分成

【imessage苹果推】群发软件安装包含(Local Notification)

1.本地推送告诉(Local Notification) 2.长途推送通知(Remote Notification) 我们在平时的开发中,利用远程推送能够比力多,远程推送依赖于加速器,需求联接才气吸收,本地推送不须联 ,增加好定时器便可在点名时辰殡葬推送,平时使用世面多是挂钟,提示等。 这边要说星子,实属iOS系统限定了挂 本地推送的数目,最大的注册量为64条。 本片语气我们首要讲授本地推送 2、本地推送(Local Push) 无需联 即可推送 不需要建立推送关系 3、push相互(示范依据iOS8.0及之上) 注册通知,获得用户受权 //

在AppDelegate.m中 // iOS10.0 需要导出 #import – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self registerAPN]; return YES; } // 注册通知 – (void)registerAPN { if (@available(iOS 10.0, *)) { // iOS10 以上 UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) { }]; } else {// iOS8.0 以上 UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:setting]; } } 添加通知 – (void)addLocalNotice { if (@available(iOS 10.0, *)) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; // 题目 content.title = @“统考标题”; content.subtitle = @“测试通知副题”; // 情节 content.body = @“测试通知的详细内容”; // 声响 // 默许声音 // content.sound = [UNNotificationSound defaultSound]; // 添加自定义声音 content.sound = [UNNotificationSound soundNamed:@“Alert_ActivityGoalAttained_Salient_Haptic.caf”]; // 角标 (我这里测试的角标无用,临时没找还缘由) content.badge = @1; // 几多秒后发送,可以将牢固的日子转发为时间 NSTimeInterval time = [[NSDate dateWithTimeIntervalSinceNow:10] timeIntervalSinceNow]; // NSTimeInterval time = 10; // repeats,是不是反复,若是重复来说时间必需有过之无不及60s,要决不会 错 UNTimeIntervalNotificationTrigger trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:time repeats:NO]; / //

如果想重复可以使用本条,按日期 // 星期一早晨 8:00 上工 NSDateComponents *components = [[NSDateComponents alloc] init]; // 注重,weekday默认是从礼拜起头 components.weekday = 2; components.hour = 8; UNCalendarNotificationTrigger *calendarTrigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES]; */ // 添加通知的终结符,可以用来移除,翻新等操纵 NSString *identifier = @“noticeId”; UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger]; [center addNotificationRequest:request withCompletionHandler:^(NSError *_Nullable error) { NSLog(@“胜利添加推送”); }]; }else { UILocalNotification *notif = [[UILocalNotification alloc] init]; // 收回推送的日期 notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10]; // 推送的内容 notif.alertBody = @“你已经10秒没呈现了”; // 可以添加一定消息 notif.userInfo = @{@“noticeId”??“00001”}; // 角标 notif.applicationIconBadgeNumber = 1; // 提醒音 notif.soundName = UILocalNotificationDefaultSoundName; // 每周轮回提醒 notif.repeatInterval = NSCalendarUnitWeekOfYear; [[UIApplication sharedApplication] scheduleLocalNotification:notif]; } } 移除通知 // 移除某一番指定的通知 – (void)removeOneNotificationWithID:(NSString *)noticeId { if (@available(iOS 10.0, *)) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray * _Nonnull requests) { for (UNNotificationRequest *req in requests){ NSLog(@“留存的ID:%@n”,req.identifier); } NSLog(@“移除currentID:%@”,noticeId); }]; [center removePendingNotificationRequestsWithIdentifiers:@[noticeId]]; }else { NSArray *array=[[UIApplication sharedApplication] scheduledLocalNotifications]; for (UILocalNotification *localNotification in array){ NSDictionary *userInfo = localNotification.userInfo; NSString *obj = [userInfo objectForKey:@“noticeId”]; if ([obj isEqualToString:noticeId]) { [[UIApplication sharedApplication] cancelLocalNotification:localNotification]; } } } } // 移除一切通知 – (void)removeAllNotification { if (@available(iOS 10.0, *)) { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center removeAllPendingNotificationRequests]; }else { [[UIApplication sharedApplication] cancelAllLocalNotifications]; } } 查抄授权环境 – (void)checkUserNotificationEnable { // 判定用户是否许可领受通知 if (@available(iOS 10.0, *)) { __block BOOL isOn = NO; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { if (settings.notificationCenterSetting == UNNotificationSettingEnabled) { isOn = YES; NSLog(@“打开了通知”); }else { isOn = NO; NSLog(@“封闭了通知”); [self showAlertView]; } }]; }else { if ([[UIApplication sharedApplication] currentUserNotificationSettings].types == UIUserNotificationTypeNone){ NSLog(@“关闭了通知”); [self showAlertView]; }else { NSLog(@“打开了通知”); } } } – (void)showAlertView { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@“通知” message:@“未获得通知权位,请前往设立” preferredStyle:UIAlertControllerStyleAlert]; ]; ; }]]; [self presentViewController:alert animated:YES completion:nil]; } // 如果用户关闭了接收通知功用,该方式可以跳转到APP设置页面停止点窜 – (void)goToAppSystemSetting { dispatch_async(dispatch_get_main_queue(), ^{ UIApplication *application = [UIApplication sharedApplication]; NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([application canOpenURL:url]) { if (@available(iOS 10.0, *)) { if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) { [application openURL:url options:@{} completionHandler:nil]; } }else { [application openURL:url]; } } }); } 被开方数参照 //上面是iOS 8.0的,iOS10.0及以上近似,具体使用可查找 fireDate:启航时间 timeZone:启动时间参考的时区 repeatInterval:重复推送时间(NSCalendarUnit范例),0委托人不重复 repeatCalendar:重复推送时间(NSCalendar类型) alertBody:通知内容 alertAction:解锁滑行时的事务 alertLaunchImage:启动贴片,设置此字段点击通知时会显现该图片 alertTitle:通知标题,合用iOS8.2以后 applicationIconBadgeNumber:收到通知时App icon的角标 soundName:推送是带的声音提醒,设置默认的字段为UILocalNotificationDefaultSoundName userInfo:发送通知时额外的内容 category:此特性和注册通知类型时相干联,(有乐趣的同窗本身领会,不解细论述)适用iOS8.0之后 region:包孕锚固的推送相干属性,具体使用见下面【带有定位的本地推送】适用iOS8.0之后 regionTriggersOnce:带有定位的推送相关属性,具体使用见下面【带有定位的本地推送】适用iOS8.0之后 通知示例 弥补:若要推送中添加图片,则可以添加以次补码: //3.载入图片 //3.1获取图片 NSString * imageUrlString = @“https://img1.doubanio.com/img/musician/large/22817.jpg”; NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrlString]]; //3.2图片保留到沙盒 NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject; NSString *localPath = [documentPath stringByAppendingPathComponent:@“localNotificationImage.jpg”]; [imageData writeToFile:localPath atomically:YES]; //3.3设置通知的attachment(备件) if (localPath && ![localPath isEqualToString:@””]) { UNNotificationAttachment * attachment = [UNNotificationAttachment attachmentWithIdentifier:@“photo” URL:[NSURL URLWithString:[@“file://” stringByAppendingString:localPath]] options:nil error:nil]; if (attachment) { content.attachments = @[attachment]; } } 4、小结 正文主要先容了本地通知的用法,将iOS8.0和10.0以上都进行了辨别,具体的使用还需要大师按照具体情况而定,但愿对大家有了帮忙。 最初,屈居Demo->>>>>传送门 5、参考 iOS10推送必看UNNotificationAttachment以及UNTimeIntervalNotificationTrigger iOS开发,本地推送的使用 iOS系统不如他提示音综述 可能有的用户在使用的进程中出现了在iOS9今后调节出现错误信息:This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release. AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager]; [mgr.responseSerializer setAcceptableContentTypes: [NSSet setWithObjects:@“application/json”, @“text/json”, @“text/javascript”,@“text/html”, nil]]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; dict[@“id”] = @“123456789”;// 你法式的apple ID [mgr POST:@“http://itunes.apple.com/cn/lookup=123456789” parameters:dict success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) { // App_URL http://itunes.apple.com/lookup NSArray *array = responseObject[@“results”]; if (array.count != 0) {//

先判断回到的多寡是否为空 没上架的时候是空的 NSDictionary *dict = array[0]; if ([dict[@“version”] floatValue] > [subVersion floatValue]) { //如果有本版本 这里要注意下如果你版本 写得是1.1.1或者1.1.1.1如许的格局,就不克不及间接转floatValue,自己想法子比较判断。 UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; alertWindow.rootViewController = [[UIViewController alloc] init]; alertWindow.windowLevel = UIWindowLevelAlert + 1; [alertWindow makeKeyAndVisible]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@“更新提示” message:@“发明新版本。为包管各条功能一般使用,请您争先更新。” preferredStyle:UIAlertControllerStyleAlert]; //显示弹出框 [alertWindow.rootViewController presentViewController:alert animated:YES completion:nil]; openURL:[NSURL URLWithString:@“https://itunes.apple.com/cn/app/id123456789=8”]]; //这里写的URL地点是该app在app store内里的下载链接地址,此中ID是该app在app store首尾相应的独一的ID数码。 NSLog(@“点击现在进级旋钮,跳转”); }]]; ]; } } } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { }]; return YES;

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年10月1日
下一篇 2021年10月1日

相关推荐