在 iPhone 中,我们可以通过编程方式设置锁屏、壁纸和铃声吗?
如果是,那么请告诉我如何设置它们?
这一切都可以轻松完成,但会被苹果拒绝。
铃声可以通过改变来改变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 应用程序中。他们并没有更多的东西,但这些应该会让你朝着正确的方向前进。
由于 iOS 的变化,WrightsCS的答案在某个时候停止工作。不幸的是,如果您希望使用未记录的功能,则必须忍受这一点。
如果您仍然需要这样做,仅适用于非 App Store 应用程序,此代码适用于 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 仅表示主屏幕。
有关为什么我动态打开此框架的解释,请参阅我的相关答案here。
我没有关于铃声的答案。这真的应该是一个单独的问题:完全不同的 API 在工作。
如果可以检查,请使用私有 apiPLStaticWallpaperImageViewController