我想在整个屏幕上放置一个UIView(包括导航栏).该视图将为黑色,具有0.3不透明度.我想这样做是为了使屏幕内容变暗并在此基础上推送视图.我正在使用此代码:
UIApplication.sharedApplication().keyWindow?.addSubview(darkView)
Run Code Online (Sandbox Code Playgroud)
这按预期覆盖整个屏幕.但是我现在想在这个黑暗的视图之上放置另一个视图.有没有办法做到这一点?我尝试的一切只会导致视图处于黑暗视野之下.任何指针都会非常感激!谢谢
撕裂我的头发,以便在iOS10中使用推送通知.目前的设置:
在func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool:
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if error == nil {
print("DID REQUEST THE NOTIFICATION")
UIApplication.shared.registerForRemoteNotifications()
}
}
print("DID SET DELEGATE")
}
Run Code Online (Sandbox Code Playgroud)
在func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data):
print("DID REGISTER FOR A REMOTE NOTIFICATION AND THE TOKEN IS \(deviceToken.base64EncodedString())"
let request = UpdatePushNotificationSubscription_Request(deviceToken: deviceToken)
updatePushNotificationSubscriptionWorker.updateSubscription(request)
Run Code Online (Sandbox Code Playgroud)
我已经检查过令牌是否正确地上传到后端,它确实匹配.
我也实施了:
@available(iOS 10.0, *) …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中实现后台刷新功能,以便在收到推送时.就在向用户显示推送通知之前,我想从后端(Parse.com)下载新消息并将它们保存到阵列中.我正在按照这里的指南:http://developer.xamarin.com/guides/ios/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/
我不确定这个指南有多准确.它指出:iOS 7(及更高版本)通过在通知用户之前为应用程序提供在后台更新内容的机会来扩展普通推送通知,以便用户可以打开应用程序并立即呈现新内容.
所以我试着像这样实现我的后台推送:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
if([[userInfo objectForKey:@"aps"] objectForKey:@"content-available"]){
NSLog(@"Doing the background refresh");
UINavigationController *navigationController=(UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
MyViewController *myViewController = (MyViewController *)[[navigationController viewControllers] objectAtIndex:1];
[myViewController.currentUser refreshMessagesArrayWithCompletionHandler:^(BOOL successful, BOOL newMiaos) {
NSLog(@"messages refreshed the array now has %lu messages",(unsigned long)[myViewController.currentUser.messages count]);
handler(UIBackgroundFetchResultNewData);
}];
}
}
Run Code Online (Sandbox Code Playgroud)
调用后台刷新并显示推送,但推送通知不等待后台任务完成.它只是在收到后立即显示.这是正确的功能吗?上面的教程建议在后台任务完成之前不会显示通知.
然后我开始尝试静默通知,这会触发应用程序在收到推送时在后台下载消息,但不会显示任何通知.因此,我通过在下载完成后触发本地通知来执行此操作.这真的是正确的做法吗?传统应用程序(如whatsapp)是否使用静默通知触发后台刷新,然后触发本地应用程序?看起来有点hacky.当然,后台推送的想法是在显示通知之前准备好数据,但它并不像那样工作.
我注意到的另一件事是静默通知是速率限制的,它们的优先级低于典型的推送通知,所以这肯定会妨碍应用程序的效率......
对此的任何指示都将非常感激.如果我正在以正确的方式接近这个问题,那就试着试试.一切似乎都非常hacky ......
我正在看一下requestReview()使用的新API SKStoreReviewController.文件说明:
"虽然您应该在应用程序的用户体验流程中调用此方法,但评级/审核请求视图的实际显示受App Store策略的控制.因为此方法可能会也可能不会显示警报,但它不是适合于响应按钮点击或其他用户操作来调用它."
有没有人有使用此API的经验.究竟是什么因素决定了评级视图是否显示?如果过于频繁地调用,我猜它没有显示..有人对此有任何见解吗?谢谢!
尝试为iOS10设置推送通知.以前它是否适用于10以下的版本.
阅读一些指南我的设置是这样的:
// Register for the defined notifications
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = UIApplication.shared.delegate as! AppDelegate
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if error == nil {
UIApplication.shared.registerForRemoteNotifications()
}
}
} else {
// Fallback on earlier versions
let notificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: [autoCancelCategory])
UIApplication.shared.registerUserNotificationSettings(notificationSettings)
UIApplication.shared.registerForRemoteNotifications()
}
Run Code Online (Sandbox Code Playgroud)
这是在我的一个视图控制器中登录^时调用的.
现在AppDelegate,它符合UNUserNotificationCenterDelegate,我有这些方法:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) …Run Code Online (Sandbox Code Playgroud) 撕掉我的头发试图让它发挥作用.我想表演[self.tableView deleteRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationLeft];,
我如何删除更详细的代码:
int index = (int)[self.messages indexOfObject:self.messageToDelete];
[self.messages removeObject:self.messageToDelete];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
NSArray *indexes = [[NSArray alloc] initWithObjects:indexPath, nil];
[self.tableView deleteRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationLeft];
Run Code Online (Sandbox Code Playgroud)
这工作正常但是如果我收到推送通知(即收到新消息),删除应用程序将崩溃并显示如下错误:
断言失败 - [UITableView _endCellAnimationsWithContext:],/ SourceCache/UIKit/UIKit-3347.44/UITableView.m:1327 2015-07-04 19:12:48.623 myapp [319:24083]***由于未捕获的异常而终止应用程序' NSInternalInconsistencyException',原因:'尝试从更新前仅包含1行的第0部分删除第1行'
我怀疑这是因为我的数据源正在改变,数组的大小
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
删除时的引用将不一致,因为当推送通知触发刷新时它会增加1.有什么方法可以解决这个问题吗?我是否正确deleteRowsAtIndexPaths使用该numberOfRowsInSection方法?
我试图用Alamofire4的Swift3.我需要下载.mp3文件并将它们保存到Documents目录中.目前的代码是这样的:
func downloadAudioFromURL(url: String, completion: ((_ status: ResponseStatus, _ audioLocalURL: URL?) -> Void)?) {
let fileManager = FileManager.default
let directoryURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
let audioFullURL = String.ensureFullURLPath(url)
alamoManager.download(audioFullURL)
.validate { request, response, temporaryURL, destinationURL in
var pathComponent = response.suggestedFilename!
if pathComponent == "m4a.mp4" {
// Due to the old Android audio files without a filename
// Assign a unique name so audio files don't overwrite each other
pathComponent = "\(NSUUID().uuidString).mp4" …Run Code Online (Sandbox Code Playgroud) 我到处寻找.试图增加这条线的厚度.无论如何以编程方式执行此操作?谢谢
我正在尝试自定义过渡动画.我创建了一个符合以下条件的动画对象UIViewControllerAnimatedTransitioning:
import UIKit
class ViewControllerAnimator: NSObject, UIViewControllerAnimatedTransitioning {
let duration = 1.0
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return duration
}
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
//Animate out
UIView.animateWithDuration(duration, animations: { () -> Void in
fromView.frame.origin.x -= 200
}) { (Bool) -> Void in
transitionContext.completeTransition(true)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试图设置框架时出错fromView.它试图强行解开零时崩溃.我在这做错了什么?为什么我的fromView没有?
在这里遇到一个只出现在某些手机上的奇怪问题。我有一个自定义的 UIView,我像这样初始化。
let passQuizToTutorAlert = SAAlertView(title: NSLocalizedString("quiz-title", comment: ""), message: String(format: NSLocalizedString("quiz-message-parameter", comment: ""), 4), textAlignment: .left, customView: headerImageView, alternativeLayout: true)
Run Code Online (Sandbox Code Playgroud)
上面的行因此错误而崩溃: Thread 1: EXC_BAD_ACCESS (code = 1, address = 0x4)
我在 init.d 中使用了各种方法。如果我使用带有参数的本地化字符串,它似乎只会崩溃。例如这里的代码没有问题:
let passQuizToTutorAlert = SAAlertView(title: NSLocalizedString("quiz-title", comment: ""), message: NSLocalizedString("quiz-message", comment: ""), textAlignment: .left, customView: headerImageView, alternativeLayout: true)
Run Code Online (Sandbox Code Playgroud)
它崩溃的本地化字符串定义如下:
"quiz-message-parameter" = "You have %d credits left";
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?为什么它只会为带有参数的本地化字符串崩溃?
编辑:
我做了一些调试。此崩溃与警报视图无关。如果我尝试:
let aString = String(format: "You have %d credits left", 4)
print(astring)
Run Code Online (Sandbox Code Playgroud)
它不会崩溃。但是当它与本地化字符串混合时它会崩溃:
let aString = String(format: NSLocalizedString("quiz-message-parameter", comment: …Run Code Online (Sandbox Code Playgroud)