解決方案:
(1)provisioning Profile文件選擇毛病
(2)provisioning Profile已失效
(3)開發(fā)者證書過(guò)期或被刪除
注:需要在Storyboard里面設(shè)置控制器的Storyboard ID
//Identifier:@“Storyboard ID”
//將storyBoard實(shí)例化 (1)(可以在AppDelegate里面使用)
UIStoryboard *mainSB = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//將要跳轉(zhuǎn)控制器通過(guò)storyBoard實(shí)例化
ViewController *VC = [mainSB instantiateViewControllerWithIdentifier:@"ViewController"];
VC.isModifyPassword = NO;
[self.navigationController pushViewController:VC animated:YES];
//將storyBoard實(shí)例化 (2)
//將要跳轉(zhuǎn)控制器通過(guò)storyBoard實(shí)例化
ViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
VC.isModifyPassword = NO;
[self.navigationController pushViewController:VC animated:YES];
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
//聲明定義1個(gè)ToastLabel對(duì)象
@interface ToastLabel : UILabel
- (void)setMessageText:(NSString *)text;
@end
@interface Toast : NSObject
{
ToastLabel *toastLabel;
NSTimer *countTimer;
NSInteger changeCount;
}
//創(chuàng)建聲明單例的方法
+ (instancetype)shareInstance;
- (void)makeToast:(NSString *)message duration:(CGFloat )duation;
@end
#import "Toast.h"
@implementation ToastLabel
/**
* ToastLabel初始化,位label設(shè)置各種屬性
*
* @return ToastLabel
*/
- (instancetype)init{
self = [super init];
if (self) {
self.layer.cornerRadius = 10;
self.layer.masksToBounds = YES;
self.backgroundColor = [UIColor blackColor];
self.numberOfLines = 0;
self.textAlignment = NSTextAlignmentCenter;
self.textColor = [UIColor whiteColor];
self.font = [UIFont systemFontOfSize:15];
}
return self;
}
/**
* 設(shè)置顯示的文字
*
* @aram text 文字文本
*/
- (void)setMessageText:(NSString *)text{
[self setText:text];
CGRect rect = [self.text boundingRectWithSize:CGSizeMake(DeviceWidth - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:self.font} context:nil];
CGFloat width = rect.size.width + 20;
CGFloat height = rect.size.height + 20;
CGFloat x = (DeviceWidth - width) / 2;
CGFloat y = DeviceHight - height - 80;
self.frame = CGRectMake(x, y, width, height);
}
@end
@implementation Toast
/**
* 實(shí)現(xiàn)聲明單例的方法 GCD
*
* @return 單例
*/
+ (instancetype)shareInstance{
static Toast *singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singleton = [[Toast alloc] init];
});
return singleton;
}
/**
* 初始化方法
*
* @return 本身
*
*/
- (instancetype)init{
self = [super init];
if (self) {
toastLabel = [[ToastLabel alloc] init];
countTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeTime) userInfo:nil repeats:YES];
countTimer.fireDate = [NSDate distantFuture];//關(guān)閉定時(shí)器
}
return self;
}
/**
* 彈出并顯示Tosat
*
* @param message 顯示的文本內(nèi)容
* @param duration 顯示時(shí)間
*/
- (void)makeToast:(NSString *)message duration:(CGFloat)duation{
if ([message length] == 0) {
return;
}
[toastLabel setMessageText:message];
[[[UIApplication sharedApplication]keyWindow ] addSubview:toastLabel];
toastLabel.alpha = 0.8;
countTimer.fireDate = [NSDate distantPast];//開啟定時(shí)器
changeCount = duation;
}
/**
* 定時(shí)器回調(diào)方法
*/
- (void)changeTime{
//NSLog(@"時(shí)間:%ld",changeCount);
if (changeCount-- <= 0) {
countTimer.fireDate = [NSDate distantFuture];//關(guān)閉定時(shí)器
[UIView animateWithDuration:0.2f animations:^{
toastLabel.alpha = 0;
} completion:^(BOOL finished) {
[toastLabel removeFromSuperview];
}];
}
}
@end
//duration:顯示的時(shí)長(zhǎng)
[[Toast shareInstance] makeToast:@"你提示的內(nèi)容" duration:1.0];
//1.創(chuàng)建UITextField種別
#import <UIKit/UIKit.h>
@interface loginUITextField : UITextField
@end
//2.重寫UITextField的左視圖的Bounds
#import "loginUITextField.h"
@implementation loginUITextField
- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
CGRect rect = [super leftViewRectForBounds:bounds];
if (self.window.frame.size.width == 320) {
rect = CGRectMake(rect.origin.x + 3, rect.origin.y , 28, 28);
} else if (self.window.frame.size.width == 375){
rect = CGRectMake(rect.origin.x + 4, rect.origin.y , 32, 32);
} else {
rect = CGRectMake(rect.origin.x + 5, rect.origin.y , 35, 35);
}
return rect;
}
@end
//以下是例子 其實(shí)不能直接使用
//_userTextField的左視圖
UIImageView *useImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user"]];
_userImageView.contentMode = UIViewContentModeScaleAspectFit;
_userTextField.leftView = useImageView;
_userTextField.leftViewMode = UITextFieldViewModeAlways;
_userTextField.borderStyle = UITextBorderStyleRoundedRect;
//修改水印字體色彩和字體大小
[_userTextField setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
[_userTextField setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
//_passwordTxetField的左視圖
UIImageView *passwdImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"locked"]];
//passwdImageView.frame = CGRectMake(0, 0, 37, 37);
_passwordTxetField.contentMode = UIViewContentModeScaleAspectFit;
_passwordTxetField.leftView = passwdImageView;
_passwordTxetField.leftViewMode = UITextFieldViewModeAlways;
_passwordTxetField.borderStyle = UITextBorderStyleRoundedRect;
//修改水印字體色彩和字體大小
[_passwordTxetField setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
[_passwordTxetField setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
//自定義NavgationBar的標(biāo)題
- (void)creatdTitle{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 45)];
label.text = @"標(biāo)題";
label.font = [UIFont boldSystemFontOfSize:20];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
}
//返回按鈕無(wú)文字的樣式
- (void)createdbackBarButtonItem{
UIBarButtonItem *newBarButtonItem = [[UIBarButtonItem alloc] init];
newBarButtonItem.title = @"";
self.navigationItem.backBarButtonItem = newBarButtonItem;
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}
//設(shè)置NavgationBar的背景圖 (jpg記得加后綴)
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"1"] forBarMetrics:UIBarMetricsDefault];
- (void)created{
NSString *str = @"注 銷";
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:str];
[alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, str.length)];
[alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:25] range:NSMakeRange(0, str.length)];
[alertController setValue:alertControllerStr forKey:@"attributedMessage"];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"肯定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[cancelAction setValue:[UIColor grayColor] forKey:@"titleTextColor"];
[alertController addAction:confirmAction];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
//self.verificationBtn:改成你自己的命名的button
- (void)startTime{
__block int timeout = 59; //倒計(jì)時(shí)時(shí)間
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒履行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒計(jì)時(shí)結(jié)束,關(guān)閉
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置(倒計(jì)時(shí)結(jié)束后調(diào)用)
[self.verificationBtn setTitle:@"獲得驗(yàn)證碼" forState:UIControlStateNormal];
[self.verificationBtn setBackgroundColor:[UIColor colorWithRed: 0/256.0 green: 111/256.0 blue: 255/256.0 alpha:1]];
//設(shè)置可點(diǎn)擊
self.verificationBtn.userInteractionEnabled = YES;
});
}else{
// int minutes = timeout / 60; //這里注釋掉了,這個(gè)是用來(lái)測(cè)試多于60秒時(shí)計(jì)算分鐘的。
int seconds = timeout % 60;
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置
//NSLog(@"____%@",strTime);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[self.verificationBtn setTitle:[NSString stringWithFormat:@"%@秒重新發(fā)送",strTime] forState:UIControlStateNormal];
[UIView commitAnimations];
self.verificationBtn.backgroundColor = [UIColor lightGrayColor];
//設(shè)置不可點(diǎn)擊
self.verificationBtn.userInteractionEnabled = NO;
});
timeout--;
}
});
dispatch_resume(_timer);
}
//頭像圖片切圓
_userImageView.layer.cornerRadius = _userImageView.frame.size.width / 2;
_userImageView.layer.masksToBounds = YES;
//
_textFiled.layer.cornerRadius = 10;
_textFiled.layer.masksToBounds = YES;
//
view.layer.cornerRadius = 20;
view.layer.masksToBounds = YES;
//創(chuàng)建個(gè)種別
#import <Foundation/Foundation.h>
@interface NSNull (IsNull)
@end
#import "NSNull+IsNull.h"
@implementation NSNull (IsNull)
- (void)forwardInvocation:(NSInvocation *)invocation
{
if ([self respondsToSelector:[invocation selector]]) {
[invocation invokeWithTarget:self];
}
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
NSMethodSignature *sig = [[NSNull class] instanceMethodSignatureForSelector:selector];
if(sig == nil) {
sig = [NSMethodSignature signatureWithObjCTypes:"@^v^c"];
}
return sig;
}
@end
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/plain",@"text/html",@"image/jpg",nil];
//1.創(chuàng)建1個(gè)類
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface CFPushHelper : NSObject
///----------------------------------------------------
/// @name Setup 啟動(dòng)相干
///----------------------------------------------------
+ (NSString *)registrationID;
/*!
* @abstract 啟動(dòng)SDK
*
* @param launchingOption 啟動(dòng)參數(shù).
* @param appKey 1個(gè)JPush 利用必須的,唯1的標(biāo)識(shí). 請(qǐng)參考 JPush 相干說(shuō)明文檔來(lái)獲得這個(gè)標(biāo)識(shí).
* @param channel 發(fā)布渠道. 可選.
* @param isProduction 是不是生產(chǎn)環(huán)境. 如果為開發(fā)狀態(tài),設(shè)置為 NO; 如果為生產(chǎn)狀態(tài),應(yīng)改成 YES.
* @param advertisingIdentifier 廣告標(biāo)識(shí)符(IDFA) 如果不需要使用IDFA,傳nil.
*
* @discussion 提供SDK啟動(dòng)必須的參數(shù), 來(lái)啟動(dòng) SDK.
* 此接口必須在 App 啟動(dòng)時(shí)調(diào)用, 否則 JPush SDK 將沒(méi)法正常工作.
*/
+ (void)setupWithOption:(NSDictionary *)launchingOption
appKey:(NSString *)appKey
channel:(NSString *)channel
apsForProduction:(BOOL)isProduction
advertisingIdentifier:(NSString *)advertisingId;
///----------------------------------------------------
/// @name APNs about 通知相干
///----------------------------------------------------
/*!
* @abstract 注冊(cè)要處理的遠(yuǎn)程通知類型
*
* @param types 通知類型
* @param categories
*
* @discussion
*/
//+ (void)registerForRemoteNotificationTypes:(NSUInteger)types
// categories:(NSSet *)categories;
//上傳deviceToken
+ (void)registerDeviceToken:(NSData *)deviceToken;
/*!
* @abstract 處理收到的 APNs 消息
*/
//+ (void)handleRemoteNotification:(NSDictionary *)userInfo;
// ios7以后,才有completion,否則傳nil
+ (void)handleRemoteNotification:(NSDictionary *)userInfo completion:(void (^)(UIBackgroundFetchResult))completion;
/*!
* @abstract 前臺(tái)展現(xiàn)本地推送
*
* @param notification 本地推送對(duì)象
* @param notificationKey 需要前臺(tái)顯示的本地推送通知的標(biāo)示符
*
* @discussion 默許App在前臺(tái)運(yùn)行時(shí)不會(huì)進(jìn)行彈窗,在程序接收通知調(diào)用此接口可實(shí)現(xiàn)指定的推送彈窗。
*/
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification identifierKey:(NSString *)notificationKey;
@end
//導(dǎo)入極光推送頭文件@"JPUSHService.h"
#import "CFPushHelper.h"
#import "JPUSHService.h"
@implementation CFPushHelper
+ (NSString *)registrationID{
return [JPUSHService registrationID];
}
+ (void)setupWithOption:(NSDictionary *)launchingOption appKey:(NSString *)appKey channel:(NSString *)channel apsForProduction:(BOOL)isProduction advertisingIdentifier:(NSString *)advertisingId{
//Required
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定義categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories 必須為nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
//Required
// 如需繼續(xù)使用pushConfig.plist文件聲明appKey等配置內(nèi)容,請(qǐng)照舊使用[JPUSHService setupWithOption:launchOptions]方式初始化。
[JPUSHService setupWithOption:launchingOption appKey:appKey
channel:channel
apsForProduction:isProduction
advertisingIdentifier:advertisingId];
return;
}
+ (void)registerDeviceToken:(NSData *)deviceToken{
[JPUSHService registerDeviceToken:deviceToken];
return;
}
//+ (void)handleRemoteNotification:(NSDictionary *)userInfo{
//
// [CFPushHelper handleRemoteNotification:userInfo];
//
//}
+ (void)handleRemoteNotification:(NSDictionary *)userInfo completion:(void (^)(UIBackgroundFetchResult))completion{
[JPUSHService handleRemoteNotification:userInfo];
if (completion) {
completion(UIBackgroundFetchResultNewData);
}
return;
}
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification
identifierKey:(NSString *)notificationKey{
[CFPushHelper showLocalNotificationAtFront:notification identifierKey:nil];
return;
}
@end
//我這里創(chuàng)建的AppDelegate的種別
#import "AppDelegate.h"
@interface AppDelegate (CFPushSDK)
- (void)JPushapplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
@end
#import "AppDelegate+CFPushSDK.h"
#import "JPUSHService.h"
#import "CFPushHelper.h"
#define JPushSDK_AppKey @"顧名思義"
#define isProduction NO
@implementation AppDelegate (CFPushSDK)
- (void)JPushapplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[CFPushHelper setupWithOption:launchOptions appKey:JPushSDK_AppKey channel:nil apsForProduction:isProduction advertisingIdentifier:nil];
//注冊(cè)
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidLoginNotification object:nil];
}
//通知方法
- (void)networkDidReceiveMessage:(NSNotification *)notification {
//調(diào)用接口
NSLog(@"\n\n極光推送注冊(cè)成功\n\n");
//通知后臺(tái)registrationID
//NSLog(@"registrationID2 = %@",[CFPushHelper registrationID]);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![CFPushHelper registrationID]) {
NSString *registrationID = @"123";
[defaults setObject:registrationID forKey:@"registrationID"];
} else {
[defaults setObject:[CFPushHelper registrationID] forKey:@"registrationID"];
}
[defaults synchronize];
//[CFPushHelper registrationID]
//注銷通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:kJPFNetworkDidLoginNotification object:nil];
}
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/// Required - 注冊(cè) DeviceToken
//NSLog(@"%@", [NSString stringWithFormat:@"Device Token: %@", deviceToken]);
[CFPushHelper registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// IOS 7 Support Required
[CFPushHelper handleRemoteNotification:userInfo completion:completionHandler];
// 利用正處理前臺(tái)狀態(tài)下,不會(huì)收到推送消息,因此在此處需要額外處理1下
if (application.applicationState == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"收到推送消息"
message:userInfo[@"aps"][@"alert"]
delegate:nil
cancelButtonTitle:@"取消"
otherButtonTitles:@"肯定",nil];
[alert show];
}
//[self gotoViewControllerWith:userInfo];
[self gotoViewController];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
//NSLog(@"did Fail To Register For Remote Notifications With Error : %@",error);
return;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
[CFPushHelper showLocalNotificationAtFront:notification identifierKey:nil];
return;
}
- (void)applicationDidBecomeActive:(UIApplication *)application{
[application setApplicationIconBadgeNumber:0];
[application cancelAllLocalNotifications];
return;
}
@end
#import "AppDelegate.h"
#import "JPUSHService.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//注冊(cè)極光推送
[self JPushapplication:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
暫時(shí)就這樣