如何在iPhone中以编程方式设置锁定屏幕,壁纸和铃声?
-
11-10-2019 - |
题
在iPhone中,我们可以通过编程方式设置锁定屏幕,壁纸和铃声吗?
如果 是的, ,然后请让我知道如何设置它们?
解决方案
这一切都可以轻松完成,但会被Apple拒绝。
铃声可以通过更改 com.apple.SpringBoard.plist
, ,特别是 ringtone
钥匙。
以下代码可用于读取自定义铃声的实际铃声标题(由iTunes同步)。
NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];
NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;
可以覆盖壁纸:
NSString *homePath1 = @"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = @"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = @"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = @"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";
这些示例用于我的Cydia应用之一。对他们来说,还有更多的东西,但是这些应该使您朝着正确的方向前进。
其他提示
这 Wrightscs的答案 由于iOS的变化,在某个时候停止工作。不幸的是,如果您想使用,这是您必须忍受的 无证件 特征。
如果您仍然需要这样做, 仅适用于非应用商店应用, ,此代码在iOS 9.3中起作用。不过,它可能会在将来的任何iOS发布中停止工作。 (请参阅下面的评论:不再在iOS 10中工作)
#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>
// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);
UIImage *wallpaper = [UIImage imageNamed: @"background.jpg"];
Class sbClass = NSClassFromString(@"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it.
// just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3]; // 3 -> set both for lock screen and home screen
dlclose(handle);
您需要将私有API标头添加到您的项目中。您通常可以通过少量搜索在线找到这些, 例如,这里.
在上面的示例中, [SBSUIWallpaperPreviewViewController setWallpaperForLocations:]
称为3:3的参数指示该图像应用于 两个都 锁和家庭屏幕。 1仅表示锁定屏幕。 2仅表示主屏幕。
有关为什么我打开这个框架的解释 动态, , 看 我的相关答案在这里.
我没有关于 铃声. 。这确实应该是一个单独的问题:工作中完全不同的API。
如果可以检查,请使用私有API PLStaticWallpaperImageViewController
不隶属于 StackOverflow